Hello! I'm trying to find the name of the current user of outlook.
I'm writing an automated email via excel-VBA, and at the end of the email, I want to write the name of the current user.
I've tried this:
Sub name()
Dim username As String, Ln As Long
Set wn = CreateObject("Wscript.Network")
username = WshNetwork.username
MsgBox (username)
End Sub
But I only get the user name of windows..
And then I tried this:
Sub username()
Set objSession = CreateObject("MAPI.Session")
' Logon using an existing MAPI session
objSession.Logon "", "", False, False, 0
' Get folder where the current Outlook item lives
Set objFolder = Item.Parent
' Get the Outlook item with CDO
Set objMessage = objSession.GetMessage(Item.EntryID, objFolder.StoreID)
' Get the sender of the message
Set objSender = objMessage.Sender
' Pull out some properties of the sender
MsgBox ("Sender name: " & objSender.Name)
MsgBox ("Sender address: " & objSender.Address)
' Close MAPI session
objSession.Logoff
End Sub
But a big error appears ([colaboration data objects - [MAPI_E_LOGON_FAILED(80040111)])
Is there a simplified way for dummies?
Thank you in advance
Bookmarks