We have prepared a tool in Excel for our Project Managers. The tool will work if they sign in to Excel using their company credentials. However, if they sign in using a personal account, it will not function.
I want to know the user’s Outlook email credentials to grant them permission to use it, or please let me know if you have any other suggestions on how to achieve this
enter image description here
Sub GetOutlookEmailAddress()
Dim OutlookApp As Object
Dim Namespace As Object
Dim CurrentUser As Object
Dim EmailAddress As String
On Error Resume Next
' Create Outlook Application object
Set OutlookApp = CreateObject("Outlook.Application")
If OutlookApp Is Nothing Then
MsgBox "Outlook is not installed or configured on this system.", vbExclamation
Exit Sub
End If
' Get Namespace object
Set Namespace = OutlookApp.GetNamespace("MAPI")
' Get the current user information
Set CurrentUser = Namespace.Session.CurrentUser
' Retrieve email address
EmailAddress = CurrentUser.AddressEntry.GetExchangeUser().PrimarySmtpAddress
' Display the email address
MsgBox "Your email address is: " & EmailAddress, vbInformation
' Clean up objects
Set CurrentUser = Nothing
Set Namespace = Nothing
Set OutlookApp = Nothing
End Sub
2