• Outlook User
  • New Outlook app
  • Outlook.com
  • Outlook Mac
  • Outlook & iCloud
  • Developer
  • Microsoft 365 Admin
    • Common Problems
    • Microsoft 365
    • Outlook BCM
    • Utilities & Addins

Automatically Create Contacts From Messages

Slipstick Systems

› Developer › Automatically Create Contacts From Messages

Last reviewed on February 24, 2022     19 Comments

This macro will go through the messages in a folder and create a contact for each sender

A user needed to solve this problem:

My contact list on a prior system was deleted. I imported all of my emails into my new Microsoft Outlook 2003 but going through all the emails individually to add contacts is horrible when you have thousands of emails. Does anyone have the micro basic code to set up a macro to add contacts from the personal favorite folder?

The user is right - its a slow, painful process to select each message, right click and choose Add to contacts. This macro solves the problem by automating the process - it goes through each message in the selected folder and creates a Contact for the sender.

For utilities that can do this or if you want to add the addresses of all people you send messages to (either new messages or replies) see Add addresses automatically to Microsoft Outlook Contacts.

This macro will work in any folder, on all selected items in that folder.

Any selected mail items will be harvested. Because Ken wanted to only use the OOM and so it's not restricted to 2007 or later only, he didn’t use the MAPI properties for SentOnBehalfOf* other than for name. So the email addresses may not be accurate (for example mails sent to a mailing list will often show as sent by the list address, not the actual sender.)

To use it, copy the code to Outlook's VB editor. If you need to run it on several folders, add a toolbar button for it. Select the messages you want to create contacts from and run it.

Tip: it might be helpful to copy messages from sender's whose address you want to save to a new folder then run it on that folder. This will allow you to peruse the messages and select just the sender's whose address you need saved.

Create Contacts for All Senders in a Folder

This macro is compliments of Outlook MVP and developer Ken Slovak from https://www.slovaktech.com

Ken adds: "If this were 2007 or later code only I’d use PropertyAccessor to pick up the PR_SENT_REPRESENTING_ADDRTYPE and PR_SENT_REPRESENTING_EMAIL_ADDRESS properties instead of using SenderEmailAddress and SenderEmailAddressType."


' The AddAddressesToContacts procedure can go in any Module
' Select the mail folder and any items to add to contacts, then run the macro

Public Sub AddAddressesToContacts()
Dim folContacts As Outlook.MAPIFolder
Dim colItems As Outlook.Items
Dim oContact As Outlook.ContactItem
Dim oMail As Outlook.MailItem
Dim obj As Object
Dim oNS As Outlook.NameSpace

Dim response As VbMsgBoxResult

Dim bContinue As Boolean

Dim sSenderName As String

On Error Resume Next

Set oNS = Application.GetNamespace("MAPI")
Set folContacts= oNS.GetDefaultFolder(olFolderContacts)
Set colItems= folContacts.Items

For Each obj In Application.ActiveExplorer.Selection
If obj.Class = olMail Then
Set oContact= Nothing

bContinue= True
sSenderName= ""

Set oMail = obj

sSenderName = oMail.SentOnBehalfOfName
If sSenderName = ";" Then
sSenderName = oMail.SenderName
End If

Set oContact = colItems.Find("[FullName] = '" & sSenderName & "'")

If Not (oContact Is Nothing) Then
response = MsgBox("This appears to be an existing contact: " & sSenderName & ". Do you still want to add it as a new contact?", vbQuestion + vbYesNo, "Contact Adder")
If response = vbNo Then
bContinue = False
End If
End If

If bContinue Then
Set oContact = colItems.Add(olContactItem)
With oContact
.Body = oMail.Subject

.Email1Address = oMail.SenderEmailAddress
.Email1DisplayName = sSenderName
.Email1AddressType = oMail.SenderEmailType

.FullName = oMail.SenderName

.Save
End With
End If
End If
Next

Set folContacts = Nothing
Set colItems = Nothing
Set oContact = Nothing
Set oMail = Nothing
Set obj = Nothing
Set oNS = Nothing
End Sub

How to use VBA

Copy and paste the code from this page into your ThisOutlookSession project. To do this, click within the code, Select All using Ctrl+A, Ctrl+C to copy.

In Outlook, press Alt+F11 to open the VBA editor and expand Microsoft Outlook Objects then double click on ThisOutlookSession to open it in the editing pane and Ctrl+P to paste the code.

For more detailed instructions and screenshots, see How to use Outlook's VBA Editor

More Information

How to use Outlook's VBA Editor
How to Create Macro in Visual Basic to add Contacts from Personal Folder - original post in our forums
Add addresses automatically to Microsoft Outlook Contacts - create contacts for people you send messages to.

Automatically Create Contacts From Messages was last modified: February 24th, 2022 by Diane Poremsky
Post Views: 86

Related Posts:

  • Macro to Create an Outlook Contact from an Email Message
  • Use Instant search to find messages from a contact
  • Change the Business Card layout using BusinessCardLayoutXml
  • Change the image on a Business Card based on the Category

About 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.

Comments

  1. Adam says

    February 25, 2016 at 3:55 pm

    How can I get it to Update or Merge a contact if it already exists? Yes I do have a need for this before anyone tells me I don't need this or shouldn't ;)

    Reply
    • Diane Poremsky says

      February 26, 2016 at 4:52 pm

      Outlook has an option to look for duplicates when a new contact is added - this won't merge the contacts there. There are utilities that will merge duplicate contacts - you could do it with a macro, but really need to display the data and choose which to keep - that is better as a com addin rather than a simple macro. I have a list of addins at https://www.slipstick.com/addins/duplicates-addins/remove-duplicate-contacts-from-outlook/ - Contacts Scrubber lets you pick the fields to keep. Others on the list may as well.

      Reply
  2. Shaun says

    February 20, 2016 at 12:19 pm

    Great article. Is there any way of modifying the code so it transfers email addresses from the To, rather than Sent From items? I have many draft emails I would like to put into contacts without having to send an email.

    Reply
    • Diane Poremsky says

      February 20, 2016 at 11:10 pm

      Try .Email1Address = oMail.To Is there more than one address in the to field? if so, you need to use the recipient collection.

      Reply
  3. WWWV says

    September 15, 2015 at 4:24 am

    Hello,

    How is it possible to add the adresses written in Sent to, CC & BCC too? So not just the sender, but basicly all the mailadresses.
    Thx.

    Reply
    • Diane Poremsky says

      September 15, 2015 at 7:05 am

      You could - you'd need to go through the recipient collection. Between the two end if's at the end, add this code. After the sender is added, it'll work on the recipients. (BTW, it won't work on the BCC field as you don't see who it was sent to. )

      For Each Recipient In oMail.Recipients
      sSenderName = Recipient.Name

      ' add recipients
      Set oContact = colItems.Find("[FullName] = '" & sSenderName & "'")

      If Not (oContact Is Nothing) Then
      response = MsgBox("This appears to be an existing contact: " & sSenderName & ". Do you still want to add it as a new contact?", vbQuestion + vbYesNo, "Contact Adder")
      If response = vbNo Then
      bContinue = False
      End If
      End If

      If bContinue Then
      Set oContact = colItems.Add(olContactItem)
      With oContact
      .Body = oMail.Subject

      .Email1Address = Recipient.Address
      .Email1DisplayName = sSenderName
      .FullName = sSenderName

      .Save
      End With
      End If
      Next Recipient

      Reply
      • Ivo says

        March 23, 2016 at 7:57 am

        thanks for this, but i get a error: "next without for"
        Here is my code:
        Public Sub AddAddressesToContacts()
        Dim folContacts As Outlook.MAPIFolder
        Dim colItems As Outlook.Items
        Dim oContact As Outlook.ContactItem
        Dim oMail As Outlook.MailItem
        Dim obj As Object
        Dim oNS As Outlook.NameSpace

        Dim response As VbMsgBoxResult

        Dim bContinue As Boolean

        Dim sSenderName As String

        On Error Resume Next

        Set oNS = Application.GetNamespace("MAPI")
        Set folContacts = oNS.GetDefaultFolder(olFolderContacts)
        Set colItems = folContacts.Items

        For Each obj In Application.ActiveExplorer.Selection
        If obj.Class = olMail Then
        Set oContact = Nothing

        bContinue = True
        sSenderName = ""

        Set oMail = obj

        sSenderName = oMail.SentOnBehalfOfName
        If sSenderName = ";" Then
        sSenderName = oMail.SenderName
        End If

        Set oContact = colItems.Find("[FullName] = '" & sSenderName & "'")

        If Not (oContact Is Nothing) Then
        response = MsgBox("This appears to be an existing contact: " & sSenderName & ". Do you still want to add it as a new contact?", vbQuestion + vbYesNo, "Contact Adder")
        If response = vbNo Then
        bContinue = False
        End If
        End If

        If bContinue Then
        Set oContact = colItems.Add(olContactItem)
        With oContact
        .Body = oMail.Subject

        .Email1Address = oMail.SenderEmailAddress
        .Email1DisplayName = sSenderName
        .Email1AddressType = oMail.SenderEmailType

        .FullName = oMail.SenderName

        .Save
        End With
        End If
        sSenderName = Recipient.Name

        ' add recipients
        Set oContact = colItems.Find("[FullName] = '" & sSenderName & "'")

        If Not (oContact Is Nothing) Then
        response = MsgBox("This appears to be an existing contact: " & sSenderName & ". Do you still want to add it as a new contact?", vbQuestion + vbYesNo, "Contact Adder")
        If response = vbNo Then
        bContinue = False
        End If
        End If

        If bContinue Then
        Set oContact = colItems.Add(olContactItem)
        With oContact
        .Body = oMail.Subject

        .Email1Address = Recipient.Address
        .Email1DisplayName = sSenderName
        .FullName = sSenderName

        .Save
        End With
        End If
        Next Recipient
        End If
        Next

        Set folContacts = Nothing
        Set colItems = Nothing
        Set oContact = Nothing
        Set oMail = Nothing
        Set obj = Nothing
        Set oNS = Nothing
        End Sub

      • Diane Poremsky says

        March 23, 2016 at 10:50 am

        that means there are too many end if, for's, next etc - it highlights on Next Recipient you either need a matching for or delete that line.

      • Ivo says

        March 23, 2016 at 9:43 am

        Fix the problem, i was missing the first line.. :-o
        What i needed was only the recipients email adress so i changed
        Set oContact = colItems.Find("[FullName] = '" & sSenderName & "'")
        to:
        Set oContact = colItems.Find("[Email1Address] = '" & sSenderName & "'")

        works like a charm, Thanks a lot!

  4. Alexandre says

    August 12, 2015 at 4:24 am

    Hello everyone,

    thank for this macro, it is very useful! I was wondering if instead of creating a new contacts in the address book, it was possible to export these informations directly into an excel file.

    Many thanks!

    Reply
    • Diane Poremsky says

      August 12, 2015 at 8:18 am

      Sure. See https://www.slipstick.com/developer/vba-copy-outlook-email-excel-workbook/ for sample code. It's just a matter of changing which fields you grab. The sample is for a run a script rule.

      Reply
  5. Colin says

    April 1, 2015 at 9:29 am

    Many thanks for posting this code. I would like to change from the default contacts folder to a specific sub folder called Test. How would I change the code for this to work.
    Many thanks
    Colin

    Reply
    • Diane Poremsky says

      April 1, 2015 at 1:06 pm

      This line sets the folder:

      Set folContacts= oNS.GetDefaultFolder(olFolderContacts)

      to use a subfolder of contacts, use

      Set folContacts= oNS.GetDefaultFolder(olFolderContacts).folders("folder name")

      More on using non-default folders: https://www.slipstick.com/developer/working-vba-nondefault-outlook-folders/

      Reply
  6. Paik says

    January 12, 2013 at 5:54 am

    @ Ilana Fridlin: Find this section in the code:
    If Not (oContact Is Nothing) Then
    (...)
    End If
    End If

    And replace it with:
    If Not (oContact Is Nothing) Then
    bContinue = False
    End If

    Reply
  7. Ilana Fridlin says

    December 10, 2012 at 6:36 am

    Is there a way to add a comand so that when it says the contact already exists and asks if I want to still add, it it automatically "clicks" on NO and keeps on going? Cause it's really unproductive to have to keep clicking NO until it ends... Please...? Or somehow that it only copies those that don't already exist...

    Reply
    • Diane Poremsky says

      December 10, 2012 at 7:33 am

      The dialog is not exposed to the object model, sorry. You would need to use a windows utility that responses to dialogs. ClickYes and others can do this.

      Reply
    • Justin Goldberg says

      August 12, 2014 at 9:32 am

      You can also use a weight or a pencil to hold down the 'N' key while you run the script. I've done this before, it works well most of the time.

      Reply
  8. Peter Zuffa says

    August 23, 2012 at 5:10 am

    Hi, there's a typo on line:

    response = MsgBox("This appears to be an existing contact: " & sSenderName" &

    The double quotes after sSenderName" must be removed.

    Peter

    Reply
    • Diane Poremsky says

      August 23, 2012 at 6:34 am

      Thanks for finding that error.

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Visit Slipstick Forums.
What's New at Slipstick.com

Latest EMO: Vol. 31 Issue 5

Subscribe to Exchange Messaging Outlook






Support Services

Do you need help setting up Outlook, moving your email to a new computer, migrating or configuring Office 365, or just need some one-on-one assistance?

Our Sponsors

CompanionLink
ReliefJet
  • Popular
  • Latest
  • Week Month All
  • Jetpack plugin with Stats module needs to be enabled.
  • Sync Issues and Errors with Gmail and Yahoo accounts
  • Error Opening iCloud Appointments in Classic Outlook
  • Opt out of Microsoft 365 Companion Apps
  • Mail Templates in Outlook for Windows (and Web)
  • Urban legend: Microsoft Deletes Old Outlook.com Messages
  • Buttons in the New Message Notifications
  • Move Deleted Items to Another Folder Automatically
  • Open Outlook Templates using PowerShell
  • Count and List Folders in Classic Outlook
  • Google Workspace and Outlook with POP Mail
Ajax spinner

Recent Bugs List

Microsoft keeps a running list of issues affecting recently released updates at Fixes or workarounds for recent issues in classic Outlook (Windows).

For new Outlook for Windows: Fixes or workarounds for recent issues in new Outlook for Windows .

Outlook for Mac Recent issues: Fixes or workarounds for recent issues in Outlook for Mac

Outlook.com Recent issues: Fixes or workarounds for recent issues on Outlook.com

Office Update History

Update history for supported Office versions is at Update history for Office

Outlook Suggestions and Feedback

Outlook Feedback covers Outlook as an email client, including Outlook Android, iOS, Mac, and Windows clients, as well as the browser extension (PWA) and Outlook on the web.

Outlook (new) Feedback. Use this for feedback and suggestions for Outlook (new).

Use Outlook.com Feedback for suggestions or feedback about Outlook.com accounts.

Other Microsoft 365 applications and services




New Outlook Articles

Sync Issues and Errors with Gmail and Yahoo accounts

Error Opening iCloud Appointments in Classic Outlook

Opt out of Microsoft 365 Companion Apps

Mail Templates in Outlook for Windows (and Web)

Urban legend: Microsoft Deletes Old Outlook.com Messages

Buttons in the New Message Notifications

Move Deleted Items to Another Folder Automatically

Open Outlook Templates using PowerShell

Count and List Folders in Classic Outlook

Google Workspace and Outlook with POP Mail

Newest Code Samples

Open Outlook Templates using PowerShell

Count and List Folders in Classic Outlook

Insert Word Document into Email using VBA

Warn Before Deleting a Contact

Use PowerShell to Delete Attachments

Remove RE:, FWD:, and Other Prefixes from Subject Line

Change the Mailing Address Using PowerShell

Categorize @Mentioned Messages

Send an Email When You Open Outlook

Delete Old Calendar Events using VBA

VBA Basics

How to use the VBA Editor

Work with open item or selected item

Working with All Items in a Folder or Selected Items

VBA and non-default Outlook Folders

Backup and save your Outlook VBA macros

Get text using Left, Right, Mid, Len, InStr

Using Arrays in Outlook macros

Use RegEx to extract message text

Paste clipboard contents

Windows Folder Picker

Custom Forms

Designing Microsoft Outlook Forms

Set a custom form as default

Developer Resources

Developer Resources

Developer Tools

VBOffice.net samples

SlovakTech.com

Outlook MVP David Lee

Repair PST

Convert an OST to PST

Repair damaged PST file

Repair large PST File

Remove password from PST

Merge Two Data Files

Sync & Share Outlook Data

  • Share Calendar & Contacts
  • Synchronize two computers
  • Sync Calendar and Contacts Using Outlook.com
  • Sync Outlook & Android Devices
  • Sync Google Calendar with Outlook
  • Access Folders in Other Users Mailboxes

Diane Poremsky [Outlook MVP]

Make a donation

Mail Tools

Sending and Retrieval Tools

Mass Mail Tools

Compose Tools

Duplicate Remover Tools

Mail Tools for Outlook

Online Services

Calendar Tools

Schedule Management

Calendar Printing Tools

Calendar Reminder Tools

Calendar Dates & Data

Time and Billing Tools

Meeting Productivity Tools

Duplicate Remover Tools

Productivity

Productivity Tools

Automatic Message Processing Tools

Special Function Automatic Processing Tools

Housekeeping and Message Management

Task Tools

Project and Business Management Tools

Choosing the Folder to Save a Sent Message In

Run Rules on messages after reading

Help & Suggestions

Submit Outlook Feature Requests

Slipstick Support Services

Buy Microsoft 365 Office Software and Services

Visit Slipstick Forums.

What's New at Slipstick.com

Home | Outlook User | Exchange Administrator | Office 365 | Outlook.com | Outlook Developer
Outlook for Mac | Common Problems | Utilities & Addins | Tutorials
Outlook & iCloud Issues | Outlook Apps
EMO Archives | About Slipstick | Slipstick Forums
Submit New or Updated Outlook and Exchange Server Utilities

Send comments using our Feedback page
Copyright © 2026 Slipstick Systems. All rights reserved.
Slipstick Systems is not affiliated with Microsoft Corporation.