Get current Outlook user

By | 2002-04-20

Retrieve the user currently logged on in the existing Microsoft Outlook session.

Original Author: Klemens Schmid

Assumptions

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.

Returns

Returns the Name property of the recipient object.

Code

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

Author: dwirch

Derek Wirch is a seasoned IT professional with an impressive career dating back to 1986. He brings a wealth of knowledge and hands-on experience that is invaluable to those embarking on their journey in the tech industry.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.