Search code examples
vbaoutlook

Get the list of all possible email addresses starting from Display Name


How could I get, with VBA Excel, the Outlook properties of a single contact for whom I have the User Principal Name?

I am interested in the tab labelled "E-mail Addresses".

I managed to get the PrimarySMTP property, but I would like to get the list of all addresses listed there. The 'alias' property gives me one entry, while there are several others.

This is what I did to get the distribution list memberships:

Dim objExchUsr As ExchangeUser 
Dim myolApp As Outlook.Application 
Dim myNameSpace As Namespace 
Dim MyAddrList As AddressList 
Dim myRecipient As Outlook.Recipient 
Dim oDistListEntries As Outlook.AddressEntries
Dim oAE As Outlook.AddressEntry

Set myolApp = CreateObject("Outlook.Application")
Set myNameSpace = myolApp.GetNamespace("MAPI")
Set MyAddrList = myNameSpace.addressLists("Global Address List")
Set myRecipient = myNameSpace.CreateRecipient(strDisplayname)
myRecipient.Resolve
If myRecipient.Resolved Then
    Set objExchUsr = myRecipient.AddressEntry.GetExchangeUser
    Set oDistListEntries = objExchUsr.GetMemberOfList
    For Each oAE In oDistListEntries
        If oAE.AddressEntryUserType = olExchangeDistributionListAddressEntry Then
            <Do something with the distribution lists: not relevant  to this problem>
        End If
    Next
End If

With this code I get the information shown in the tab 'Member Of' of the Outlook Properties. How do I get the information that is shown in the tab 'E-mail Addresses'?


Solution

  • Here is the code you could use:

    Const PR_EMS_AB_PROXY_ADDRESSES  As String = _
    "http://schemas.microsoft.com/mapi/proptag/0x800F101F"
    
    Dim NS As Outlook.NameSpace
    Set NS = Application.GetNamespace("MAPI")
    
    addresses = _
    NS.CurrentUser.AddressEntry.PropertyAccessor.GetProperty(PR_EMS_AB_PROXY_ADDRESSES)