How to include pictures in a Microsoft Word mail mergeBy Jim Gordon, co-author of Office 2011 for Mac All-in-One For Dummies

You can make name badges, ID cards, personalized email messages or even elaborate catalogs using Word mail merge. Follow these instructions to take to include pictures in a mail merge in Microsoft Word 2011. You should download and install the Free MVP Word toolbar because will be using 3 of the toolbar’s buttons. You don’t have to learn all the stuff about the toolbar to follow along with this tutorial. This tutorial is pretty exacting, so please scan through the instructions and make sure you feel up to the task.

Preparation
Before you can merge, you'll need a folder that contains the pictures and you'll need a data source.

The pictures folderMake a folder that contains the pictures you want to use in your merge. Not every picture type is supported in mail merge. I know that JPEG (.jpg) pictures will work. All the pictures to be used must be in one folder. In this example, my pictures folder has four files and I called the folder EmployeePics:Mary.jpgTom.jpgJustin.jpgMolly.jpg

The data sourceThe data source can be an Excel workbook. You can copy and paste this table into an Excel Workbook and then save the workbook to use for an example data source. Notice that the Picture File Name column has the names of the picture files that you put into the folder WITHOUT file extension. That's important.

First Name / Last Name / Picture File Name
Mary / Smith / Mary
Thomas / Jones / Tom
Justin / Quick / Justin
Megan / Time / Molly

Setting up the Word mail merge documentTo illustrate using a picture in a mail merge, you will make a simple form letter.

1.  Open a new, blank Microsoft Word document. Use Word’s Print Layout view.

2.  Save the word document.

3.  From Word’s Tools menu, choose Mail Merge Manager (MMM) to display the manager if it is not already showing.

4.  In MMM step 1, choose Create New > Form Letters.

5.  In MMM step 2, click the Get List button and from the pop-down menu choose Open Data Source…

6.  The Choose a File dialog opens. Choose the Excel data source workbook that you saved earlier.

7.  In the resulting dialog that tells you a text converter will be used, click the OK button.

8.  In the dialog that shows the sheet names of the workbook, click the top pop-up menu and choose the sheet that contains the data table to use for merging. Tip: In the future, whenever you open the Word document, remember to choose the same sheet from the list.

9.  Click the Save button on the standard toolbar or press ⌘-s to save the mail merge Word document

At this point you have a completely blank mail merge document connected to our Excel data source workbook. Next, you will add placeholders to the document from the MMM.

10.  In MMM step 3, drag the First Name placeholder to the mail merge Word document, then press a space.

11.  In MMM step 3, drag the Last Name placeholder to the mail merge Word document, and then press Return.

12.  In MMM step 5, click the triangle to expose the Preview Results section

13.  In MMM step 5, click the first button <ABC> View Merged Data

14.  In MMM step 5, click the red buttons to move through the data

At this point you should be able to see the data from the Excel workbook refresh using the red buttons. If you click the <ABC> View Merged Data button repeatedly, you should toggle between showing the names of the contact fields and the names in the data source table. So far this is all standard procedure for mail merge. Next, you can work with the pictures. You need to get the full file path of one of the pictures, and you can get it this way:

15.  Click the Finder button on your dock (the blue smiling face) to open a Finder window

16.  In the search field in the upper right corner of the Finder window, type the name of one of the picture files, such as Mary.jpg

17.  In the resulting list of files, select the name of the file that is in the pictures folder to be used as the data source in the merge.

18.  Right click on the name of the picture file, and choose Get Info from the resulting pop-up menu

19.  In the General section of the Get Info dialog, in the Where section, select the text that has the file path and then choose Edit > Copy or press ⌘-c to copy the file path to the Mac OS clipboard.

20.  Click into the mail merge document to give it the focus of the computer’s attention.

21.  Press ⌘-v or choose Edit > Past to paste the file path into the mail merge Word document.

22.  You have almost the full file path, but you need to type a slash and the file name, such as /Mary.jpg to make the file path complete. The full file path should like something like this: /Users/JBG/Documents/Databases/MM Include Picture/EmployeePics/Mary.jpg

23.  Select the text of the file path, and copy it to the Mac OS clipboard using Edit > Copy or ⌘-c.

Now you have the file path of one picture on the clipboard so you won’t have to type so much. Now you can link the picture to our mail merge document.

24.  Click into the mail merge Word document and choose Edit > Paste or press ⌘-v to paste the file path into the document body.

25.  Replace each slash / with a full colon : in the file name.

26.  Select the complete modified file path in the Word document and copy it to the clipboard using Edit > Copy or ⌘-c

27.  Click the Field button on the MVP toolbar, or from the Insert menu choose Field to display the Field dialog.

28.  In the Field dialog, under categories choose Links and References.

29.  In the Field dialog, under Field Names choose IncludePicture.

30.  In the input box, type two quotation marks. See screen shot:

31.  In the input box, click between the two quotation marks you just typed, and press ⌘-v to paste the file path from the Mac OS clipboard into the field so that the file path is within the quotation marks.

32.  Click the OK button. The picture should now appear in the mail merge Word document.

Now replace the file name of the picture with a merge field.

33.  In MMM step 5, click the View All Placeholders button, or click the {a} View All Placeholders button on the MVP toolbar. The picture is replaced by the text of the Field Code you entered.

34.  Click into the INCLUDEPICTURE Field Code and delete the name of the file, but keep the file extension. In the example so far, delete Mary but keep the colon and .jpg and keeping all the rest of the field code unaltered.

35.  In MMM step 3, from Contacts drag the field that is the one for the pictures in the data table and position it exactly between the colon and the file extension. This adds a {MERGEFIELD photo} set of brackets to the INCLUDEPICTURE field code.

The INCLUDE picture Word Field should look something like this: { INCLUDEPICTURE "Macintosh HD:Users:JBG:Documents:Databases:MM Include Picture:EmployeePics:«Picture_File_Name».jpg" \* MERGEFORMAT } with chevrons around the field name you used for the photos column of your data source. Next, test to make sure everything is working.

36.  In MMM step 5, click the {a} View All Placeholders button, or click the {a} View All Placeholders button on the MVP toolbar so that you display the picture instead of the field code.

37.  In MM step 5, choose a different record by clicking the buttons next to the record number, or by typing a different record number into the box. Toggle display of data by clicking the ABC View Merged Data button. As you choose different records notice that the text information changes, but the picture does not update.

38.  Select the picture by clicking it once.

39.  While the picture is selected, click the Update Field button on the MVP toolbar. If you click the Update Field button the MVP toolbar after you change the record number, you should see the picture update to the proper picture for each record.

Note: Updating the field code won’t work unless you have used colons instead of slashes in the file path. Ordinarily, you can right-click on a field code and choose update field from the pop-up menu, but that doesn’t work with INCLUDEPICTURE, so you do need to click the Update Field button on the MVP toolbar to refresh the picture for each different record.

If you made it this far, congratulations! You’ve got INCLUDEPICTURE working in a mail merge. I would love to tell you all you have to do is Complete Merge in MM step 6, but unfortunately, that won’t work (the picture won’t update for each record). To complete the merge you need to turn to the magic of Visual Basic for Applications (VBA). You will enter the Visual Basic Editor, which is like a word processor for computer code. Then, you will put the computer code into a “module,” which is somewhat like a word processing document.

40.  On the Tools menu choose Macro > Visual Basic Editor, or click the Visual Basic Editor button on the MVP toolbar to display the Visual Basic Editor (VBE). Don’t be scared, but a little apprehension is OK.

41.  In the Visual Basic Editor, on the Insert menu choose Module to open a window that looks like a blank Word document.

42.  Copy the following code and paste it into the module, then read through the code starting at the top so you get an idea of what the code will do when it is run. You can make a loop instead of pasting the code over and over again for each record, but that’s a different lesson. Make sure you follow the instructions within the code where you must substitute the name of the mail merge Word document you are using within the quotation marks for each record after the first one.

Sub DoTheMerge()

'Merge the first record to a new document

'Notice the active record is the first record

ActiveDocument.MailMerge.DataSource.ActiveRecord = wdFirstRecord

With ActiveDocument.MailMerge

.Destination = wdSendToNewDocument

.Execute

End With

'

'The following section is repeated for each record (except the first one) in the merge. The example has 4 records, so the code is repeated 3 more times

'

'Return focus to the mail merge document

'Put the file name of your mail merge document in the quotation marks in the next line

Windows("MMDocument.doc [Compatibility Mode]").Activate

'Notice the active record is the next record

ActiveDocument.MailMerge.DataSource.ActiveRecord = wdNextRecord

Selection.Fields.Update

With ActiveDocument.MailMerge

.Destination = wdSendToNewDocument

.Execute

End With

'

'Return focus to the mail merge document

'Put the file name of your mail merge document in the quotation marks in the next line

Windows("MMDocument.doc [Compatibility Mode]").Activate

'Notice the active record is the next record

ActiveDocument.MailMerge.DataSource.ActiveRecord = wdNextRecord

Selection.Fields.Update

With ActiveDocument.MailMerge

.Destination = wdSendToNewDocument

.Execute

End With

'

'Return focus to the mail merge document

'Put the file name of your mail merge document in the quotation marks in the next line

Windows("MMDocument.doc [Compatibility Mode]").Activate

'Notice the active record is the next record

ActiveDocument.MailMerge.DataSource.ActiveRecord = wdNextRecord

Selection.Fields.Update

With ActiveDocument.MailMerge

.Destination = wdSendToNewDocument

.Execute

End With

'

End Sub

43.  After making the changes to the file name of your own Word document, in the Visual Basic Editor’s Word menu choose Close and Return to Microsoft Word, or press ⌘-q to return to your mail merge Word document.

44.  Click the Save button on the standard toolbar, or press ⌘-s to save the mail merge Word document.

45.  On the Tools menu, choose Macro > Macros… to display the Macros dialog.

46.  In the Macros dialog, select DoTheMerge and then click the Run button.

If you followed the instructions carefully and have the right file name in the macro, then Word will generate 4 new documents, each with the name of the employee and their picture. Congratulations! You have succeeded in making your first Word mail merge with pictures.

The example merges the records to a new Word document, but you can easily change the destination by replacing the destination in the VBA code. Here are the valid codes:

.Destination = wdSendToNewDocument

.Destination = wdSendToEmail

.Destination = wdSendToFax

.Destination = wdSendToPrinter

I have not tried each destination to make sure the code works.

Jim Gordon's MVP Home