Get current users primary e-mail

coveredinbutter

New Member
Joined
Dec 20, 2021
Messages
19
Office Version
  1. 365
Platform
  1. 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:

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.
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: VBA to get current users primary e-mail
There is no need to repeat the link(s) provided above but if you have posted the question at other places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0
Good to hear you got the solution.
Readers here may not be a member at the other forum and therefore would not be able to see the solution, only the following message.
1674687044393.png


Therefore, if you would like to post the solution here then it is perfectly fine to mark your post as the solution to help future readers. Otherwise, please do not mark a post that doesn't contain a solution.
 
Upvote 0
Solution:

VBA Code:
Set oExchUser = OL.Session.CurrentUser.AddressEntry.GetExchangeUser()
 
Upvote 0
Solution

Forum statistics

Threads
1,223,979
Messages
6,175,761
Members
452,668
Latest member
mrider123

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top