Mailbox API, How to get Firstname and Lastname of the contact. RRS feed

  • Question

  • Good day Outlook devs! 

    I am currently creating an office apps which is actually a mail application on outlook. The problem is, instead of using DisplayName on the API which results to contact's FullName, i would like to separate it to Firstname and Lastname. I've seen the API chart but i cant see the firstname and lastname in there. Is there other way to get the firstname and lastname of the contact on the outlook? is there another API that i can use to get those information? please help me. 



    Thursday, January 23, 2014 2:31 AM


  • Hello Ricky,

    There is no need to use any other APIs.

    The ContactItem class from the Outlook Object Model provides the FirstName and LastName properties. But it looks like you are talking about the DisplayName property of the Account class. You need to use the following code to get the corresponding ContactItem object:

    Public Sub test()
      Dim ns As Outlook.NameSpace
      Dim accounts As Outlook.accounts
      Dim account As Outlook.account
      Dim recipient As Outlook.recipient
      Dim addrEntry As Outlook.AddressEntry
      Dim contact As Outlook.ContactItem
      Set ns = Application.Session
      Set accounts = ns.accounts
      Set account = accounts.Item(1)
      Set recipient = account.CurrentUser
      Set addrEntry = recipient.AddressEntry
      Set contact = addrEntry.GetContact()
    MsgBox contact.FirstName + contact.LastName, vbInformation, "First and Last names"
    End Sub
    The Account class provides the CurrentUser property which returns a Recipient object that represents the current user identity for the account. The Recipient class provides the AddressEntry property which returns the AddressEntry object corresponding to the resolved recipient. Finally, the GetContact method of the AddressEntry class returns a ContactItem object that represents the AddressEntry,  if the AddressEntry corresponds to a contact in an Outlook Contacts Address Book  (CAB). Be aware that it returns Null (Nothing in Visual Basic) if the AddressEntry object does not correspond to  a contact in a Contacts Address Book.
    • Marked as answer by Marvin_Guo Friday, February 7, 2014 11:55 AM
    Thursday, January 23, 2014 11:20 AM