I have found several articles on the web that made mail merge using a SharePoint 2010 list as the data source possible which has spawned this post. The instructions I found online were great, up to a certain point, however. Most of the instructions assumed the users had some basic understanding and thus many steps were omitted which reduces the target audience that can use their instructions considerably. These instructions are intended for folks who have not worked with the Visual Basic Macro editor and don’t have a lot of interest in learning how to do it. They just want to get their work done.
I have created the following test documents and test SharePoint lists for these instructions. You will need to do the same for your project.
- Create Data Source list in SharePoint 2010
- Open Notepad and save an empty file as TestMergeSource.odc to the following location
- C:\Program Files (x86)\Microsoft Office\Office14\QUERIES
- Open Microsoft Word (2007 or 2010)
- Save Word document as TestMergeDocument.docx to SharePoint 2010 document library location noted above
- In Word document click View tab
- Click View Macros (see below)
- Enter a name in the Macro name: field (no spaces)
- I named mine Test_Merge_Source
- Select All active templates and documents in the Macros in: drop down (see below)
- Click Create button
- Paste the below code into the Visual Basic Editor replacing bolded sections with your filenames
- (NOTE: If you have more than one macro, your editor may have multiple Sub sections, this is ok)
Sub Test_Merge_Source() ‘ ‘ Test_Merge_Source Macro ‘ Combines files to produce form letters, mailing labels, envelopes, and catalogs ‘ ‘ List name Const strList As String = “Mail Merge Data Source“ ‘ Site URL Const strDatabase As String = “http://your.domain.com“ ‘ Office Database Connection file Const strODC As String = “C:\Program Files (x86)\Microsoft Office\Office14\QUERIES\TestMergeSource.odc“ ActiveDocument.MailMerge.MainDocumentType = wdNotAMergeDocument ActiveDocument.MailMerge.OpenDataSource _ Name:=strODC, _ Connection:= _ “Provider=Microsoft.ACE.OLEDB.12.0;” & _ “Data Source=” & strDatabase & “;” & _ “Mode=Share Deny None;” & _ “Extended Properties=””WSS;HDR=NO;IMEX=2;” & _ “DATABASE=” & strDatabase & “;” & _ “LIST=” & strList & “;””;”, _ sqlstatement:= _ “SELECT * FROM [” & strList & “]” End Sub
- Your completed code will look like the image below with no other Macros present, if you do have others your code will look different
- Click Save when done
- Close the Visual Basic Editor screen
- Back in Word click the Macros button and click View Macros again
- You should now see the newly created Macro named Test_Merge_Source (or whatever you named yours… see below)
- Select your Macro and click Run
- Click the Mailings tab
- Click the Edit Recipients List button in the Start Mail Merge section
- Validate the recipients list is accurate (see below)
- If all is correct, create your document as you normally would and then save the document.
- You will not need to repeat these steps unless you move to a different computer or remove the code added above
You can also use this macro for other Word Documents that you want to use the same data source. This is why I recommend saving the macro with a name specific to the data source (SharePoint List).