Grab Alias of Selected Message RRS feed

  • Question

  • I provide software support.  Most requests for support are received by Outlook email messages.  

    When I receive a message I have to right click the name of the sender and then open up the Outlook Properties.  I do this to find the Alias of the sender which at our company contains the Windows username of the person.

    I usually want the Alias of the Sender and everyone else to whom the message was sent for the message that I received and have selected in the Explorer.

    How can I find the the Aliases of each person in a selected message using VBA?


    Friday, May 9, 2014 4:02 PM


All replies

  • Hello John,

    It looks like you are interested in the Alias property of the ExchangeUser and ExchangeDistributionList classes. For example:

    Sub DemoAE()  
     Dim colAL As Outlook.AddressLists  
     Dim oAL As Outlook.AddressList  
     Dim colAE As Outlook.AddressEntries  
     Dim oAE As Outlook.AddressEntry  
     Dim oExUser As Outlook.ExchangeUser  
     Set colAL = Application.Session.AddressLists  
     For Each oAL In colAL  
     'Address list is an Exchange Global Address List  
     If oAL.AddressListType = olExchangeGlobalAddressList Then  
     Set colAE = oAL.AddressEntries  
     For Each oAE In colAE  
     If oAE.AddressEntryUserType = _  
     olExchangeUserAddressEntry Then  
     Set oExUser = oAE.GetExchangeUser  
     End If  
     End If  
    End Sub

    Friday, May 9, 2014 4:09 PM
  • See MailItem.Sender.GetExchangeUser().Alias.
    Friday, May 9, 2014 4:12 PM
  • Hi Eugene, this works great to get the Sender:


    Is there a way to do the same thing using "To"

    Something like:



    • Edited by JohnDurbin Friday, May 9, 2014 6:16 PM
    Friday, May 9, 2014 5:47 PM
  • Hello John,

    Try using the following chain of calls:


    Friday, May 9, 2014 6:17 PM

    Thank you so much...JD


    Friday, May 9, 2014 6:37 PM
  • I have another question and hope you won't mind.

    I want to take what I've learned from you and populate an Outlook UserForm textbox with the aliases.

    On the textbox I have Multiline = True and EnableKeyBehavior = True

    Unfortunately, when the UserForm opens it contains only one recipient even though there are many.

    Would you have any suggestions?...JD

    Sub PopulateUForm()
    Dim msg As outlook.MailItemSet
    msg = GetMailItem
    Dim i As Integer
    i = msg.Recipients.Count
    Dim str As String
    For x = 1 To i
    str = msg.Recipients.item(x).AddressEntry.GetExchangeUser.Alias & Chr(13)
    UserForm2.TextBox1.Value = str
    Next x
    End Sub


    Friday, May 9, 2014 8:01 PM
  • For the GetMailItem I found some code that look like this:

    Function GetMailItem() As outlook.MailItem
      On Error Resume Next
      Select Case TypeName(Application.ActiveWindow)
        Case "Explorer"
          If TypeName(ActiveExplorer.Selection.item(1)) = "MailItem" Then
            Set GetMailItem = ActiveExplorer.Selection.item(1)
          End If
        Case "Inspector"
          If TypeName(ActiveInspector.CurrentItem) = "MailItem" Then
            Set GetMailItem = ActiveInspector.CurrentItem
          End If
      End Select
      On Error GoTo 0
    End Function


    Friday, May 9, 2014 8:08 PM
  • John,

    First of all, I'd recommend asking separate questions in new forum threads. Thus, forum readers may recognize questions and answers easier.

    You need to concatenate strings, see Concatenation Operators in Visual Basic .

    Friday, May 9, 2014 8:40 PM