README.md

December 4, 2022 ยท View on GitHub

Get current Outlook user

Description

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

More Info

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 the Name property of the recipient object.

Submitted On
ByKlemens Schmid
LevelBeginner
User Rating4.0 (8 globes from 2 users)
CompatibilityVB 4.0 (32-bit), VB 5.0, VB 6.0
CategoryMiscellaneous
WorldVisual Basic
Archive File

Source 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