# Word 2010 Mail Merge to save to individual .docx files



## jk1234 (Jan 17, 2014)

I'm new to VBA and have not worked with macros in word much.

I have a form that is a large table covering an entire page. The form has custom margins:

TopMargin = (0.5)
BottomMargin = (0.19)
LeftMargin = (0.6)
RightMargin = (0.6)

I have been attempting to do a mail merge to add assigned acct rep, account number, period ending, and account type to the form. So far I have been able to export and split them; however, the formatting is off so there is a second blank page added onto each checklist. One thing I have been trying to do is I to alter the saved split document to have the accounts name and account number in the file name. I was working off of an old post on here with no luck:

http://www.mrexcel.com/forum/genera...010-mail-merge-save-individual-pdf-files.html

The code that ended up partially working for me is:

Sub BreakOnSection()
' Used to set criteria for moving through the document by section.
Application.Browser.Target = wdBrowseSection
'A mailmerge document ends with a section break next page.
'Subtracting one from the section count stop error message.
For i = 1 To ((ActiveDocument.Sections.Count) - 1)

'Select and copy the section text to the clipboard
ActiveDocument.Bookmarks("\Section").Range.Copy
'Create a new document to paste text from clipboard.
Documents.Add
Selection.Paste
' Removes the break that is copied at the end of the section, if any.
Selection.MoveUp Unit:=wdLine, Count:=1, Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=1
ChangeFileOpenDirectory "C:\ChecklistLocation"
DocNum = DocNum + 1
ActiveDocument.SaveAs FileName:="AnnualAudit_" & DocNum & ".doc"
ActiveDocument.Close
' Move the selection to the next section in the document
Application.Browser.Next
Next i
ActiveDocument.Close savechanges:=wdDoNotSaveChanges
End Sub


I found the code that worked (partially) at: WD: How to Programmatically Save Each Page or Section of Document As Separate File

I'm not sure how to add any additional functionality to the macro. Any help is greatly appreciated!


----------



## Macropod (Jan 23, 2014)

Since you're using vba, you'd probably do better to use that to drive the whole merge process, merging & saving one record at a time. It's far easier to ensure consistency in the output format that way than to try to split the consolidated output where the mailmerge main document either: a) uses a page layout is not the same as the template upon which it is based; or b) uses hard-formatting to override any Style definitions.

For some code, see: http://www.gmayor.com/individual_merge_letters.htm


----------

