Word 2010 Mail Merge to save to individual .docx files

jk1234

New Member
Joined
Jan 17, 2014
Messages
1
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!
 
Last edited:

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
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
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top