Macro to Create an Outlook Contact from an Email Message

Last reviewed on March 7, 2014   —  2 comments

Outlook has a really easy way to create a contact from an email message: right click on an address in the From, To, or CC field and choose Add to Outlook Contacts. This creates a contact with the display name and email address entered into a new Contact form.

That's how it works in older versions of Outlook but it doesn't work like this in Outlook 2013 and it's very frustrating.

In Outlook 2013, your experience will vary when you are signed in to LinkedIn or Facebook using the Social Connector. If Outlook finds a match in Facebook or LinkedIn, Outlook thinks a contact exists and Edit Contact is enabled. If you click Save, an Outlook Contact is created, using the LinkedIn name (which may not be the display name used on the message). The email address is added only if you are linked to the person on LinkedIn.

No linkedin Contact Has LinkedIn Contact

Fortunately, I can use a macro to create a contact for the sender. I often save contacts in my SharePoint contacts folder and the macro can handle that too.

I'm using one macro to set the destination folder then calling a second macro to create the contact in that folder. This allows me to use several Contact folders as the destination, without repeating the entire code over and over.

No-macro method: drag the message to People in the Folder Bar to create a new contact for the sender in the default Contacts folder.

Create Contacts for Email Senders

To use this macro, create buttons on the ribbon for each macro that sets a folder. Then select a message in the message list and click one of the buttons.

Public objDestFolder As Outlook.Folder
Sub SaveInSPS()
    Dim objNS As Outlook.NameSpace
    Set objNS = Application.GetNamespace("MAPI")
    Set objDestFolder = objNS.Folders("SharePoint Lists").Folders("SPS Contacts")
' After setting the folder, call the macro that creates the contact
    CreateContactFromMail
End Sub

Sub CreateContact()
    Dim objNS As Outlook.NameSpace
    Set objNS = Application.GetNamespace("MAPI")
    Set objDestFolder = objNS.GetDefaultFolder(olFolderContacts)
' After setting the folder, call the macro that creates the contact
    CreateContactFromMail
End Sub

Sub CreateContactFromMail()

    Dim ObjItem As ContactItem
    Dim sSenderName As String
    Dim oMail As Outlook.MailItem
     
' to work with open or selected messages, use the
' GetCurrentItem() function from http://slipstick.me/e8mio
    Set oMail = Application.ActiveExplorer.Selection.Item(1)
    sSenderName = oMail.SentOnBehalfOfName
        If sSenderName = ";" Then
        sSenderName = oMail.SenderName
        End If
Debug.Print
    Set ObjItem = objDestFolder.Items.Add(olContactItem)
        With ObjItem
            .Body = oMail.Subject
            .Email1Address = oMail.SenderEmailAddress
            .Email1DisplayName = sSenderName
            .Email1AddressType = oMail.SenderEmailType
            .FullName = oMail.SenderName
            .Display
        End With
   
    Set objDestFolder = Nothing
    
Set ObjItem = Nothing
Set objDestFolder = Nothing

End Sub

How to use macros

First: You will need macro security set to low during testing.

To check your macro security in Outlook 2010 or 2013, go to File, Options, Trust Center and open Trust Center Settings, and change the Macro Settings. In Outlook 2007 and older, it’s at Tools, Macro Security.

After you test the macro and see that it works, you can either leave macro security set to low or sign the macro.

Open the VBA Editor by pressing Alt+F11 on your keyboard.

To put the code in a module:

  1. Right click on Project1 and choose Insert > Module
  2. Copy and paste the macro into the new module.

More information as well as screenshots are at How to use the VBA Editor

Written by

Diane Poremsky
A Microsoft Outlook Most Valuable Professional (MVP) since 1999, Diane is the author of several books, including Outlook 2013 Absolute Beginners Book. She also created video training CDs and online training classes for Microsoft Outlook. You can find her helping people online in Outlook Forums as well as in the Microsoft Answers and TechNet forums.

Please post long or more complicated questions at Outlookforums.

2 responses to “Macro to Create an Outlook Contact from an Email Message”

  1. Rick Spiewak

    Your macro is a little more flexible because it can handle SharePoint, but for regular Outlook contact creation there is a great third-party application for this that I've used for years - Copy2Contact. You just use a hot-key after highlighting the signature and everything is put into place in a new contact.

    Regards,
    Rick Spiewak

Leave a Reply

If the Post Coment button disappears, press your Tab key.