PDA

View Full Version : Splitting word document into multiple documents



atoo
03-19-2014, 03:15 PM
Hi,

I am trying to split one word document into multiple documets (I am using mail merge, it is one template and I change only names, adress etc.).
I am using this makro (found on MS web):

Sub BreakOnPage()
' Used to set criteria for moving through the document by page.
Application.Browser.Target = wdBrowsePage

For i = 1 To ActiveDocument.BuiltInDocumentProperties("Number of Pages")

'Select and copy the text to the clipboard.
ActiveDocument.Bookmarks("\page").Range.Copy

' Open new document to paste the content of the clipboard into.
Documents.Add
Selection.Paste
' Removes the break that is copied at the end of the page, if any.
Selection.TypeBackspace
ChangeFileOpenDirectory "C:\"
DocNum = DocNum + 1
ActiveDocument.SaveAs FileName:="test_" & DocNum & ".doc"
ActiveDocument.Close

' Move the selection to the next page in the document.
Application.Browser.Next
Next i
ActiveDocument.Close savechanges:=wdDoNotSaveChanges
End Sub

But I need to keep style, font, header, footer etc. of the splitting document in the new ones (the same as the document which is splitting). Does anybody know how to do it? Thank you.

PS: Sorry for my english. :)

macropod
03-19-2014, 03:45 PM
For two approaches, one to send the merge output to individual files at the time of creation, the other the split the output afterwards, see: http://www.excelforum.com/word-formatting-and-general/997510-splitting-and-renaming-mailmerge-doc-new-to-macros.html

PS: When posting code, please use the code tags. They're on the 'Go Advanced' tab.