It took me a while to figure out how to do this, even with a KB article.
First, you need to place the macro in Normal.dotm ... Open C: \ Users \ Yourname \ AppData \ Roaming \ Microsoft \ Templates \ Normal.dotm in Word, press Alt-F11 and paste the following into Module1:
Sub BreakOnSection() Application.ScreenUpdating = False 'Makes the code run faster and reduces screen flicker a bit. ' Used to set criteria for moving through the document by section. Application.Browser.Target = wdBrowseSection strBaseFilename = ActiveDocument.Name On Error GoTo CopyFailed 'A mail merge document ends with a section break next page. 'Note: Document may or may not end with a section break, For I = 1 To ActiveDocument.Sections.Count '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 DocNum = DocNum + 1 strNewFileName = Replace(strBaseFilename, ".do", "_" & Format(DocNum, "000") & ".do") ActiveDocument.SaveAs "C:\Destination\" & strNewFileName ActiveDocument.Close ' Move the selection to the next section in the document. Application.Browser.Next Next I Application.Quit SaveChanges:=wdSaveChanges End CopyFailed: 'MsgBox ("No final Section Break in " & strBaseFilename) Application.Quit SaveChanges:=wdSaveChanges End End Sub
Save the Normal.dotm file.
Executing this code will split the document, consisting of several sections, into several documents in the C: \ Destination directory, and then close Word.
You can do this from the command line with:
"c:\Program Files\Microsoft Office\Office12\WINWORD.EXE" /mBreakOnSection "C:\Path to Source\Document with multiple sections.doc"
To process all .doc files in a directory, create a batch file as follows and execute it:
@ECHO off set "dir1=C:\Path to Source" echo running FOR %%X in ("%dir1%\*.doc") DO "c:\Program Files\Microsoft Office\Office12\WINWORD.EXE" /mBreakOnSection "%%~X" echo Done pause
source share