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

Print Contacts and Contact Photos

Slipstick Systems

› Outlook › People › Print Contacts and Contact Photos

Last reviewed on February 8, 2018     9 Comments

This code sample creates a Word document containing the selected contact's name, address, phone number and contact photo. This sample uses a new, blank Word document, however, you could use a Word template with either bookmarks or merge fields for the contact data.

contact printout with contact photos

In my code sample:

  • If the contact has a home address or phone, that is used in the printout, else the business address or phone is used.
  • If a photo is not assigned to the contact, it uses a placeholder image.
  • The contact photos are scaled to 36 pixels high. If the image is more then 134 pixels wide after the height is scaled, the image is reduced to 100 pixels wide.
  • The document is hidden until the macro finishes. If you want to watch the macro create the entries, put oWord.Visible = True right after oWord.Documents(1).Activate.

To use, paste the code into the VBA editor and create a folder under Documents called Logos. Rename an image placeholder.jpg, to use for contacts who don't have a photo and put it in the logos folder. Select the contacts you want to print (use Ctrl+A to select all) then run the macro.

This is a Outlook macro. You need to set a reference to the Word object library in the VBA editor's Tools, References menu.

 Option Explicit
 
Public Sub MergeContactPhoto()
    Dim Session As Outlook.NameSpace
    Dim currentExplorer As Explorer
    Dim Selection As Selection
    Dim oContact As ContactItem
    Dim attach As Attachment
    Dim obj As Object
    Dim strFilename As String
    Dim filename As String
    Dim imagePath As String
    Dim oWord As Word.Application
    
    Dim strAddress As String
    Dim strNumber As String
    ' Uses current user's profile
    Dim enviro As String
    enviro = CStr(Environ("USERPROFILE"))
    ' Get Word
    On Error Resume Next
  Set oWord = GetObject(, "Word.Application")
        If oWord Is Nothing Then
           Set oWord = CreateObject("Word.Application")
       End If

' open a new word doc
oWord.Documents.Add
oWord.Documents(1).Activate

    Set currentExplorer = Application.ActiveExplorer
    Set Selection = currentExplorer.Selection

  If Not TypeOf Selection.Item(1) Is Outlook.ContactItem Then
  MsgBox "You need to select Contacts first!"
  Exit Sub
  End If

For Each obj In Selection

'Test for ContactGroups
 If TypeName(obj) = "ContactItem" Then
 Set oContact = obj

' Save the contact photo
strFilename = ""
For Each attach In oContact.Attachments
    strFilename = strFilename & ";" & attach.filename
Next

If InStr(strFilename, "ContactPicture.jpg") Then
   For Each attach In oContact.Attachments
        If attach.filename = "ContactPicture.jpg" Then
            filename = oContact.FirstName & oContact.LastName & ".jpg"
            imagePath = enviro & "\Documents\Logos\" & filename
            attach.SaveAsFile imagePath
            Exit For
        End If
    Next
Else
    imagePath = enviro & "\Documents\Logos\placeholder.png"
End If

If Not oContact.HomeAddress = "" Then
strAddress = " - Home: " & oContact.HomeAddressStreet & ", " & oContact.HomeAddressCity & ", " & oContact.HomeAddressState & vbCrLf
ElseIf Not oContact.BusinessAddress = "" Then
strAddress = " - Business: " & oContact.BusinessAddressStreet & ", " & oContact.BusinessAddressCity & ", " & oContact.BusinessAddressState & vbCrLf
Else
strAddress = vbCrLf
End If

If Not oContact.HomeTelephoneNumber = "" Then
strNumber = "Home phone: " & oContact.HomeTelephoneNumber
ElseIf Not oContact.BusinessTelephoneNumber = "" Then
strNumber = "Business Phone: " & oContact.BusinessTelephoneNumber
Else
strNumber = vbCrLf
End If

Dim shp As Word.Shapes
Dim logo As Word.Shape
Dim rng As Word.Range
Set rng = oWord.Selection.Range
oWord.Selection.TypeText Text:=oContact.FullName & strAddress
oWord.Selection.TypeText Text:=strNumber
oWord.Selection.TypeParagraph

Set shp = oWord.Documents(1).Shapes

' add the new logo
 Set logo = shp.AddPicture(filename:=imagePath, LinkToFile:=False, _
        SaveWithDocument:=True, Anchor:=rng, Left:=3, Top:=-3)

 ' use same wrap format as placeholder
 logo.WrapFormat.Type = wdWrapSquare

' height and width are in pixels
' 1 inch = 72 pixels
        
If logo.Height > 40 Then
 With logo
  .LockAspectRatio = True
  .Height = 36
  .Apply
End With
End If

If logo.Width > 134 Then
 With logo
  .LockAspectRatio = True
  .Width = 100
  .Apply
End With
End If

End If

    Next
   oWord.Visible = True
 
' oWord.Documents(1).PrintOut PrintToFile:=True
     
    Set oWord = Nothing
    Set obj = Nothing
    Set Selection = Nothing
    Set currentExplorer = Nothing
    Set Session = Nothing
End Sub

How to use the Macro

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

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, it’s at Tools, Macro Security. If Outlook tells you it needs to be restarted, close and reopen Outlook. Note: after you test the macro and see that it works, you can either leave macro security set to low or sign the macro.

Now 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
If you receive a "User-defined type not defined" error, you need to set a reference to another object library. For this macro, it would be Word's object library.

  1. Go to Tools, References menu.
  2. Locate the object library in the list and add a check mark to it.
    Reference the Word object model in Outlook's VBA Editor

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

Print Contacts and Contact Photos was last modified: February 8th, 2018 by Diane Poremsky

Related Posts:

  • Print Outlook Business Card Images
  • How to replicate Outlook's New letter to Contact feature using a custo
    Create a Letter to a Contact using VBA
  • Mail merge and Send from a Distribution Group
  • Mail Merge to Email using an Outlook Macro

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

Steve Garbett
December 22, 2016 9:42 am

HI there - could you tell me where i can find the word object model?

Many thanks

0
0
Reply
Diane Poremsky
Author
Reply to  Steve Garbett
March 20, 2017 1:13 am

It's listed in Tool, References under Microsoft Word Object Library.

0
0
Reply
John Hendershot
August 31, 2015 5:58 pm

First time through running this and I get "Compile error: user-defined type not defined" for the line which reads, "Dim oWord As Word.Application". (I have been looking for this capability for years - so close, so far). I know practically nothing about macros; left off programming back at Fortran IV. Can fix

0
0
Reply
Diane Poremsky
Author
Reply to  John Hendershot
January 9, 2016 6:31 pm

You need to add the Word object model in the VBA editor's Tools, References to avoid that error message.

0
0
Reply
John Hendershot
Reply to  Diane Poremsky
January 9, 2016 8:38 pm

Will try it - thanks,

0
0
Reply
Bills
Reply to  Diane Poremsky
December 9, 2017 11:33 pm

Dear Diane !!

I am getting same error "user-defined type not defined" in the line
"Dim Session As Outlook.NameSpace"
and I have already checked
"Outlook Addinlib"
"Outlook ChangeNotifierAddin 1.0 Type Library"
in "References" of Tool menu
Also, I have outlook already configured in my laptop with a working outlook email id.

Kindly guide the solution.

0
0
Reply
Diane Poremsky
Author
Reply to  Bills
December 10, 2017 7:48 pm

Are you using the macro in outlook or word? it's an outlook macro. Also, those two libraries you checked should be unchecked; one is the itunes sync addin, not sure about the other one, but they don't have any effect on this.

0
-1
Reply
Bills
Reply to  Diane Poremsky
December 9, 2017 11:36 pm

And I am using Ms Word 2016

0
0
Reply
Diane Poremsky
Author
Reply to  Bills
December 10, 2017 7:51 pm

While the macro could be tweaked to work in word, its an outlook macro.

0
0
Reply

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

Latest EMO: Vol. 30 Issue 29

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

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

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

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.

:wpds_smile::wpds_grin::wpds_wink::wpds_mrgreen::wpds_neutral::wpds_twisted::wpds_arrow::wpds_shock::wpds_unamused::wpds_cool::wpds_evil::wpds_oops::wpds_razz::wpds_roll::wpds_cry::wpds_eek::wpds_lol::wpds_mad::wpds_sad::wpds_exclamation::wpds_question::wpds_idea::wpds_hmm::wpds_beg::wpds_whew::wpds_chuckle::wpds_silly::wpds_envy::wpds_shutmouth:
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