coveredinbutter
New Member
- Joined
- Dec 20, 2021
- Messages
- 19
- Office Version
- 365
- Platform
- Windows
Hi There,
I'm trying to get the primary e-mail of the current user, and I have code that works. The problem is, there are often multiple users in my organization with the same name, so it depending on their order in the address book, it will sometimes grab the wrong e-mail.
Code I'm using:
Appreciate any help.
I'm trying to get the primary e-mail of the current user, and I have code that works. The problem is, there are often multiple users in my organization with the same name, so it depending on their order in the address book, it will sometimes grab the wrong e-mail.
Code I'm using:
VBA Code:
Sub GetCurrentUsersEmailAddress()
Dim OL, olAllUsers, oExchUser, oentry, myitem As Object
Dim User, varActiveEmail As String
Set OL = CreateObject("outlook.application")
Set olAllUsers = OL.Session.AddressLists.Item("All Users").AddressEntries
User = OL.Session.CurrentUser.Name
Set oentry = olAllUsers.Item(User)
Set oExchUser = oentry.GetExchangeUser()
varActiveEmail = oExchUser.PrimarySmtpAddress
End Sub
Appreciate any help.