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

Add Contact Information to a Task

Slipstick Systems

› Developer › Code Samples › Add Contact Information to a Task

Last reviewed on October 27, 2021     No Comments

If you are creating a task and want to include contact information you have two options within Outlook:
Enable the Contact field on the task form or copy and paste the information from the contact.

If you frequently add the same contact information to your tasks, you can use a macro to get the contact fields you need and add a hyperlink back to the contact.

You can use these macros to add information from more than one contact to a task.

These macros would work with calendar items as well, just update the form type.

Use Address Book to pick the contact

With this macro, you pick a contact from the Address Book and the contact information is added to a task body. The macro is designed to work from an open task form or you can run the macro, select the contact and add it to a new task form.

This macro will work with multiple contact folders, provided the contact folders are enabled as Outlook address books. Note that if you have two contacts with the same email address it will return the first match it finds.

This will not work with shared contacts folders (use Select Contact from any Contact folder instead).

  1. Set up the macro and add a macro button to your ribbon or the Quick Access Toolbar, in both the main Outlook window and an open Tasks form as it will check to see if the current item is a task and add the contact information to it. If the current item is not a task, it will create a new task with the contact information.
  2. Click the button to run the macro.
    click a button to add contact info to a task
  3. Select the contact from your address book. Select the Contact then click OK; no need to click To first.
    select from the address book
  4. The pre-defined contact fields are added at the top of the task body.
    contact info added to task

If you need to add another contact's information to the task, click the button again.

Sub AddContactsToTaskAB()
Dim Ns As Outlook.NameSpace
Dim olApp As Outlook.Application
Dim oDialog As SelectNamesDialog

Dim olRecip As Recipient
Dim olAddrEntry As AddressEntry
Dim objContact As ContactItem
Dim objTask As TaskItem

Dim objInsp As Inspector
Dim objDoc As Word.Document
Dim objSel As Word.Selection

Dim oEmail As String
Dim oFName As String
Dim oBizPhone As String
Dim oBday As String
Dim strLink, strLinkText As String

  Set Ns = Application.GetNamespace("MAPI")
  Set olApp = GetObject(, "Outlook.Application")
    
  Set oDialog = Ns.GetSelectNamesDialog

  With oDialog
    .AllowMultipleSelection = False
    .ShowOnlyInitialAddressList = False
    If .Display Then
      oEmail = oDialog.Recipients.Item(1).Address
      Debug.Print "oEmail: " & oEmail
          
                        
    Set olRecip = Ns.CreateRecipient(oEmail)
    olRecip.Resolve
    Set olAddrEntry = olRecip.AddressEntry
    Set objContact = olAddrEntry.GetContact
      If Not (objContact Is Nothing) Then
        'this is a contact
        'olCont is ContactItem object
        Debug.Print objContact.FullName
      End If
    End If
  End With
                        
            
 With objContact
    oFName = .FullName
    oBday = .Birthday
    oBizPhone = .BusinessTelephoneNumber
    strID = .EntryID
 End With
 
 If oBday = "1/1/4501" Then oBday = "Birthdate not available"

strLink = "outlook:" & strID
   
If olApp.ActiveInspector.CurrentItem.MessageClass = "IPM.Task" Then
' use already open task
Set objTask = olApp.ActiveInspector.CurrentItem
Else
' open new task
Set objTask = olApp.CreateItem(olTaskItem)
End If

Set objInsp = objTask.GetInspector
Set objDoc = objInsp.WordEditor
Set objSel = objDoc.Windows(1).Selection

With objTask
' to insert at insertion point, remove this line
   objDoc.Bookmarks("\StartOfDoc").Select

    objSel.Range.InsertParagraphBefore
' add link to contact
    objDoc.Hyperlinks.Add objSel.Range, strLink, "", "", oFName, ""
    objSel.Range.InsertBefore oEmail & vbCrLf & oBizPhone & vbCrLf & oBday
    objSel.Range.InsertParagraphBefore
' add a copy of the contact - link is better
    '.Attachments.Add objContact
    .Save
    .Display
End With
 
Set objTask = Nothing
Set objContact = Nothing
Set oDialog = Nothing
Set Ns = Nothing
Set olApp = Nothing
End Sub

 

Select Contact from any Contact folder

This version of the macro works with any contacts folder, even if it's not enabled as an Outlook Address Book. Add the macro to the Contact ribbon or Quick Access Toolbar. Select the contact from a contacts folder, run the macro to add a link to the contact to the task body.

As with the previous macro, it will work with an open task form or creates a new task if the last opened item is not a task. To add another contact to the same task, select another contact and run the macro.

  1. Select the contact and run the macro.
    add contact to task
  2. The contact fields are added to the top of the task body.
    contact added to task

' link contact to task
Sub AddContactLinkToTask()
Dim olApp As Outlook.Application
  Dim objTask As Outlook.TaskItem
  Dim objContact As Outlook.ContactItem
  Dim oEmail As String
  Dim oFName As String
  Dim oBizPhone As String

  Dim strID As String
  Dim strLink As String
  Dim objInsp As Inspector
  Dim objDoc As Word.Document
  Dim objSel As Word.Selection

Set olApp = GetObject(, "Outlook.Application")
Set objContact = Application.ActiveExplorer.Selection.Item(1)

With objContact
    oFName = .FullName
    oBizPhone = .BusinessTelephoneNumber
    strID = .EntryID
    strLink = "outlook:" & strID
End With

If olApp.ActiveInspector.CurrentItem.MessageClass = "IPM.Task" Then
' use already open task
Set objTask = olApp.ActiveInspector.CurrentItem
Else
' open new task
Set objTask = olApp.CreateItem(olTaskItem)
End If

Set objInsp = objTask.GetInspector
Set objDoc = objInsp.WordEditor
Set objSel = objDoc.Windows(1).Selection

With objTask
   objDoc.Bookmarks("\StartOfDoc").Select
   objSel.Range.InsertParagraphBefore
   objDoc.Hyperlinks.Add objSel.Range, strLink, "", "", oFName, ""
  objSel.Range.InsertAfter oEmail & vbCrLf & oBizPhone & vbCrLf
    
    '.Attachments.Add objContact
    .Save
    .Display
End With
 
    Set objTask = Nothing
    Set objContact = Nothing
End Sub

 

Add Contact information to Appointment

To convert the macro to work with appointments, you need to change task to appointment in the DIM statement and for the message class. You can leave the object name (objTask) but changing it to objAppt might be less confusing.

As with the task macro, run the macro and pick the contact entry from the Outlook Address Book.

Dim Ns As Outlook.NameSpace
Dim olApp As Outlook.Application
Dim oDialog As SelectNamesDialog

Dim olRecip As Recipient
Dim olAddrEntry As AddressEntry
Dim objContact As ContactItem
Dim objAppt As AppointmentItem

Dim objInsp As Inspector
Dim objDoc As Word.Document
Dim objSel As Word.Selection

Dim oEmail As String
Dim oFName As String
Dim oBizPhone As String
Dim oBday As String
Dim strLink, strLinkText As String

  Set Ns = Application.GetNamespace("MAPI")
  Set olApp = GetObject(, "Outlook.Application")
    
  Set oDialog = Ns.GetSelectNamesDialog

  With oDialog
    .AllowMultipleSelection = False
    .ShowOnlyInitialAddressList = False
    If .Display Then
      oEmail = oDialog.Recipients.Item(1).Address
      Debug.Print "oEmail: " & oEmail
          
                        
    Set olRecip = Ns.CreateRecipient(oEmail)
    olRecip.Resolve
    Set olAddrEntry = olRecip.AddressEntry
    Set objContact = olAddrEntry.GetContact
      If Not (objContact Is Nothing) Then
        'this is a contact
        'olCont is ContactItem object
        Debug.Print objContact.FullName
      End If
    End If
  End With
                       
            
 With objContact
    oFName = .FullName
    oBday = .Birthday
    oBizPhone = .BusinessTelephoneNumber
    strID = .EntryID
 End With
 
 If oBday = "1/1/4501" Then oBday = "Birthdate not available"

strLink = "outlook:" & strID
   
If olApp.ActiveInspector.CurrentItem.MessageClass = "IPM.Appointment" Then
' use already open task
Set objAppt = olApp.ActiveInspector.CurrentItem
Else
' open new task
Set objAppt = olApp.CreateItem(olAppointmentItem)
End If

Set objInsp = objAppt.GetInspector
Set objDoc = objInsp.WordEditor
Set objSel = objDoc.Windows(1).Selection

With objAppt
' remove this line to insert at cursor position
   objDoc.Bookmarks("\StartOfDoc").Select

    objSel.Range.InsertParagraphBefore
' add link to contact
    objDoc.Hyperlinks.Add objSel.Range, strLink, "", "", oFName, ""
    objSel.Range.InsertBefore oEmail & vbCrLf & oBizPhone & vbCrLf & oBday
    objSel.Range.InsertParagraphBefore
' add a copy of the contact - link is better
    '.Attachments.Add objContact
   ' .Save
    .Display
End With
 
Set objAppt = Nothing
Set objContact = Nothing
Set oDialog = Nothing
Set Ns = Nothing
Set olApp = Nothing
End Sub

Available Contact fields

Contact Field NameEquivalent Outlook object model property
AccountAccount
AnniversaryAnniversary
Assistant's NameAssistantName
Assistant's PhoneAssistantTelephoneNumber
AttachmentAttachments
Billing InformationBillingInformation
BirthdayBirthday
Business AddressBusinessAddress
Business Address CityBusinessAddressCity
Business Address CountryBusinessAddressCountry
Business Address PO BoxBusinessAddressPostOfficeBox
Business Address Postal CodeBusinessAddressPostalCode
Business Address StateBusinessAddressState
Business Address StreetBusinessAddressStreet
Business FaxBusinessFaxNumber
Business Home PageBusinessHomePage
Business PhoneBusinessTelephoneNumber
Business Phone 2Business2TelephoneNumber
CallbackCallbackTelephoneNumber
Car PhoneCarTelephoneNumber
CategoriesCategories
ChildrenChildren
CityHomeAddressCity
CompanyCompanyName
Company Main PhoneCompanyMainTelephoneNumber
Computer Network NameComputerNetworkName
CountryHomeAddressCountry
CreatedCreationTime
Customer IDCustomerID
DepartmentDepartment
EmailEmail1Address
Email 2Email2Address
Email 3Email3Address
File AsFileAs
First NameFirstName
Flag StatusFlagStatus
Follow-up FlagFlagRequest
FTP SiteFTPSite
Full NameFullName
GenderGender
Government ID NumberGovernmentIDNumber
HobbiesHobby
Home AddressHomeAddress
Home Address CityHomeAddressCity
Home Address CountryHomeAddressCountry
Home Address PO BoxHomeAddressPostOfficeBox
Home Address Postal CodeHomeAddressPostalCode
Home Address StateHomeAddressState
Home Address StreetHomeAddressStreet
Home FaxHomeFaxNumber
Home PhoneHomeTelephoneNumber
Home Phone 2Home2TelephoneNumber
In FolderParent
InitialsInitials
Internet Free Busy AddressInternetFreeBusyAddress
ISDNISDNNumber
Job TitleJobTitle
LanguageLanguage
Last NameLastName
LocationLocation
Mailing AddressMailingAddress
Manager's NameManagerName
Message ClassMessageClass
Middle NameMiddleName
MileageMileage
Mobile PhoneMobileTelephoneNumber
ModifiedLastModificationTime
NicknameNickName
NotesBody
Office LocationOfficeLocation
Organizational ID NumberOrganizationalIDNumber
Other AddressOtherAddress
Other Address CityOtherAddressCity
Other Address CountryOtherAddressCountry
Other Address PO BoxOtherAddressPostOfficeBox
Other Address Postal CodeOtherAddressPostalCode
Other Address StateOtherAddressState
Other Address StreetOtherAddressStreet
Other FaxOtherFaxNumber
Other PhoneOtherTelephoneNumber
Outlook Internal VersionOutlookInternalVersion
Outlook VersionOutlookVersion
PagerPagerNumber
Personal Home PagePersonalHomePage
PO BoxHomeAddressPostOfficeBox
Primary PhonePrimaryTelephoneNumber
PrivateSensitivity
ProfessionProfession
Radio PhoneRadioTelephoneNumber
ReadUnRead
Referred ByReferredBy
ReminderReminderSet
Reminder TimeReminderTime
SensitivitySensitivity
SizeSize
SpouseSpouse
StateHomeAddressState
Street AddressHomeAddressStreet
SubjectSubject
SuffixSuffix
TelexTelexNumber
TitleTitle
TTY/TDD PhoneTTYTDDTelephoneNumber
User Field 1User1
User Field 2User2
User Field 3User3
User Field 4User4
Web PageWebPage
ZIP/Postal CodeHomeAddressPostalCode

How to use the macros on this page

First: You need to have macro security set to the lowest setting, Enable all macros during testing. The macros will not work with the top two options that disable all macros or unsigned macros. You could choose the option Notification for all macros, then accept it each time you restart Outlook, however, because it's somewhat hard to sneak macros into Outlook (unlike in Word and Excel), allowing all macros is safe, especially during the testing phase. You can sign the macro when it is finished and change the macro security to notify.

To check your macro security in Outlook 2010 and newer, go to File, Options, Trust Center and open Trust Center Settings, and change the Macro Settings. In Outlook 2007 and older, look 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.

Macros that run when Outlook starts or automatically need to be in ThisOutlookSession, all other macros should be put in a module, but most will also work if placed in ThisOutlookSession. (It's generally recommended to keep only the automatic macros in ThisOutlookSession and use modules for all other macros.) The instructions are below.

The macros on this page should be placed in a module.

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.

Set a reference to other Object Libraries
This macro requires a reference set to Microsoft Word Object Library. You will receive a "User-defined type not defined" error if the reference is not set.

  1. Go to Tools, References menu.
  2. Locate the object library in the list and add a check mark to it. (Word and Excel object libraries version numbers will match Outlook's version number.)
    Reference the Word object model in Outlook's VBA Editor

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

Add Contact Information to a Task was last modified: October 27th, 2021 by Diane Poremsky

Related Posts:

  • Create an Appointment at the Contact's Address
  • Create Task or Appointment and Insert Selected Text
  • Create a Task and copy to another Tasks folder
  • Replicate GTD: Create a task after sending a message

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
0 Comments
newest
oldest most voted
Inline Feedbacks
View all comments

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

Latest EMO: Vol. 30 Issue 16

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
  • Use Classic Outlook, not New Outlook
  • How to Remove the Primary Account from Outlook
  • Disable "Always ask before opening" Dialog
  • This operation has been cancelled due to restrictions
  • Adjusting Outlook's Zoom Setting in Email
  • How to Hide or Delete Outlook's Default Folders
  • Reset the New Outlook Profile
  • Save Attachments to the Hard Drive
  • Outlook SecureTemp Files Folder
  • Add Attachments and Set Email Fields During a Mail Merge
  • 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