Use this macro to create and print a Microsoft Word document containing Outlook's business cards.
The macro saves the card as a jpg image then inserts it into a Word document.
Option Explicit
Public Sub MergeContactPhoto()
Dim currentExplorer As Explorer
Dim Selection As Selection
Dim oContact As ContactItem
Dim obj As Object
Dim filename As String
Dim imagePath As String
Dim oWord As Word.Application
Dim i As Long
' 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
oWord.Visible = True
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
i = i + 1
' Save the business card
filename = oContact.FirstName & oContact.LastName & ".jpg"
imagePath = enviro & "\Documents\Cards\" & filename
oContact.SaveBusinessCardImage (imagePath)
' add the new business card to the word doc
oWord.Selection.InlineShapes.AddPicture filename:=imagePath, LinkToFile:=False, _
SaveWithDocument:=True
oWord.Selection.TypeText Text:=" "
End If
If i = 2 Then
oWord.Selection.TypeParagraph
i = 0
End If
Next
' uncomment to send to printer
' oWord.Documents(1).PrintOut PrintToFile:=True
Set oWord = Nothing
Set obj = Nothing
Set currentExplorer = Nothing
Set Selection = Nothing
Set Session = 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:
- Right click on Project1 and choose Insert > Module
- Copy and paste the macro into the new module.
More information as well as screenshots are at How to use the VBA Editor