• 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

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.

Subscribe
Notify of
19 Comments
newest
oldest most voted
Inline Feedbacks
View all comments

Adam (@guest_196735)
February 25, 2016 3:55 pm
#196735

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 ;)

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  Adam
February 26, 2016 4:52 pm
#196777

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.

0
0
Reply
Shaun (@guest_196627)
February 20, 2016 12:19 pm
#196627

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.

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  Shaun
February 20, 2016 11:10 pm
#196628

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

0
0
Reply
WWWV (@guest_193303)
September 15, 2015 4:24 am
#193303

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.

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  WWWV
September 15, 2015 7:05 am
#193305

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

0
0
Reply
Ivo (@guest_197388)
Reply to  Diane Poremsky
March 23, 2016 7:57 am
#197388

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… Read more »

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  Ivo
March 23, 2016 10:50 am
#197396

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.

0
0
Reply
Ivo (@guest_197392)
Reply to  Diane Poremsky
March 23, 2016 9:43 am
#197392

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!

0
0
Reply
Alexandre (@guest_192482)
August 12, 2015 4:24 am
#192482

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!

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  Alexandre
August 12, 2015 8:18 am
#192486

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.

0
0
Reply
Colin (@guest_190153)
April 1, 2015 9:29 am
#190153

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

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  Colin
April 1, 2015 1:06 pm
#190161

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/

0
0
Reply
Paik (@guest_173280)
January 12, 2013 5:54 am
#173280

@ 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

0
0
Reply
Ilana Fridlin (@guest_172806)
December 10, 2012 6:36 am
#172806

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

0
0
Reply
Diane Poremsky (@guest_172807)
Reply to  Ilana Fridlin
December 10, 2012 7:33 am
#172807

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.

0
-1
Reply
Justin Goldberg (@guest_185152)
Reply to  Ilana Fridlin
August 12, 2014 9:32 am
#185152

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.

0
0
Reply
Peter Zuffa (@guest_168051)
August 23, 2012 5:10 am
#168051

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

0
0
Reply
Diane Poremsky (@guest_168097)
Reply to  Peter Zuffa
August 23, 2012 6:34 am
#168097

Thanks for finding that error.

0
0
Reply

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

Latest EMO: Vol. 30 Issue 19

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.
  • Open Outlook Templates using PowerShell
  • Count and List Folders in Classic Outlook
  • Google Workspace and Outlook with POP Mail
  • Import EML Files into New Outlook
  • Opening PST files in New Outlook
  • New Outlook: Show To, CC, BCC in Replies
  • Insert Word Document into Email using VBA
  • Delete Empty Folders using PowerShell
  • Warn Before Deleting a Contact
  • Classic Outlook is NOT Going Away in 2026
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

Open Outlook Templates using PowerShell

Count and List Folders in Classic Outlook

Google Workspace and Outlook with POP Mail

Import EML Files into New Outlook

Opening PST files in New Outlook

New Outlook: Show To, CC, BCC in Replies

Insert Word Document into Email using VBA

Delete Empty Folders using PowerShell

Warn Before Deleting a Contact

Classic Outlook is NOT Going Away in 2026

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 © 2025 Slipstick Systems. All rights reserved.
Slipstick Systems is not affiliated with Microsoft Corporation.

wpDiscuz

Sign up for Exchange Messaging Outlook

Our weekly Outlook & Exchange newsletter (bi-weekly during the summer)






Please note: If you subscribed to Exchange Messaging Outlook before August 2019, please re-subscribe.

Never see this message again.

You are going to send email to

Move Comment