by Klemens Schmid (9 Submissions)
Category: Miscellaneous
Compatability: Visual Basic 3.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating:
(2 Votes)
Retrieve the user currently logged on in the existing Microsoft Outlook session.
Assumes
Open a new VB project. Add a button to the form. Add a reference to "Microsoft Outlook ...". Paste the code into the form. Run the project.
Code Returns
Returns the Name property of the recipient object.
Private Sub cmdUser_Click()
'get the user from the current Outlook session
Dim ol As Outlook.Application
Dim ns As NameSpace
Dim oRec As Recipient
Set ol = New Outlook.Application
Set ns = ol.GetNamespace("MAPI")
Call ns.Logon(, , , False)
Set oRec = ns.CurrentUser
MsgBox oRec.Name
End Sub