Get the logged in users email and manager

Copper Contributor

Hi 

 

I need to get the currently logged in users email and manager. I have the username as per code below.

 

Sub GetLoggedInUserCredentials()
'Declare variables
Dim strUserName As String
Dim strPrincipal As String
Dim strUserEmail As String
'Get system logged in user name, manager and principal
strUserName = Environ("Username") 'This works
strPrincipal = Environ("Manager") '??? not sure what must go here, not sure Environ is the right thing looking to use Azure AD
strUserEmail = Environ("UserEmail") '???

Worksheets("Setup").Range("N17") = strUserName 'This works
Worksheets("Setup").Range("N20") = strPrincipal
Worksheets("Setup").Range("N21") = strUserEmail
End Sub

3 Replies

@ChrisPWC 

Email address and Manager aren't environment variables.

See Get email address from Active Directory 

@Hans Vogelaar Hi Thanks for the quick response. I get the error as per the screenshot attached

 

 

@ChrisPWC 

I'm afraid I cannot help you with this, sorry.