VBA & Macro Problems

Split a Word Document into Six-Page Files with VBA

Aamir Naveed AkramAamir Naveed Akram Nov 20, 2026 868 views

Question details

Automatically divide a large Word document into separate files containing up to six pages each.

Split a Word Document into Six-Page Files with VBA
Product
Microsoft Word
Device & OS
not provided
Scenario
A single Word file contains multiple six-page sets that need to be saved as individual documents.
Observed behavior
A previous macro attempt produced error 91, and creating the files manually would be time-consuming.
Before you start

Open the document in desktop Word and save a copy to a local folder. Check its page layout and page count before splitting; pagination can change when content is placed in a new document.

Solution 1Recommended

Run a VBA macro to save six-page ranges as separate files

Use this Windows desktop Word macro to create files from consecutive six-page ranges without cutting content from the source.

The macro calculates page boundaries in the source document and copies each range into a new document. The last file may contain fewer than six pages.

New documents can reflow differently from the source. Headers, footers, floating objects, section formatting, and blank pages may not transfer as expected, so review each output file.

1
Open the VBA editor

In Word, open the locally saved document to split. Press Alt+F11, then select Insert > Module.

2
Paste the macro

Paste this code into the module: Sub SplitEverySixPages() Dim src As Document, dst As Document Dim pageStart As Range, nextStart As Range Dim totalPages As Long, firstPage As Long Dim startPos As Long, endPos As Long, fileNumber As Long Dim outputPath As String, filePrefix As String Set src = ActiveDocument If src.Path = "" Then MsgBox "Save the source document to a local folder first." Exit Sub End If src.Repaginate totalPages = src.ComputeStatistics(wdStatisticPages) filePrefix = src.Path & "\Split_" & Format(Now, "yyyymmdd_hhnnss") & "_" fileNumber = 1 For firstPage = 1 To totalPages Step 6 Set pageStart = src.GoTo(What:=wdGoToPage, Which:=wdGoToAbsolute, Count:=firstPage) startPos = pageStart.Start If firstPage + 6 <= totalPages Then Set nextStart = src.GoTo(What:=wdGoToPage, Which:=wdGoToAbsolute, Count:=firstPage + 6) endPos = nextStart.Start Else endPos = src.Content.End End If outputPath = filePrefix & Format(fileNumber, "000") & ".docx" If Dir(outputPath) <> "" Then MsgBox "Output file already exists: " & outputPath Exit Sub End If Set dst = Documents.Add dst.Content.FormattedText = src.Range(Start:=startPos, End:=endPos).FormattedText dst.SaveAs2 FileName:=outputPath, FileFormat:=wdFormatXMLDocument dst.Close SaveChanges:=wdDoNotSaveChanges fileNumber = fileNumber + 1 Next firstPage MsgBox "Created " & (fileNumber - 1) & " files in " & src.Path End Sub

3
Run the macro

Return to Word, keep the source document active, and select Developer > Macros. Choose SplitEverySixPages and select Run. Enable macros only if you trust the code.

4
Check the output files

Open the new Split_ files in the source document's folder. Check their page counts, content, headers, footers, and layout against the corresponding source pages.

Run a VBA macro to save six-page ranges as separate files
About error 91: Error 91 means an object variable has not been set. This macro uses Set for the source document, target document, and page ranges before using them.
Free Microsoft Office alternative

Review split Word files with WPS Writer

WPS Office is a free, lightweight alternative with a familiar interface for opening and reviewing Word documents. Its format compatibility makes it easy to move existing files over, although it does not fix or guarantee compatibility with Microsoft Word VBA macros.

Open and review the layout of split document filesCompatible with Microsoft Word DOC and DOCX formatsUse a familiar interface to edit existing documentsMove documents from Microsoft Office without starting over
microsoft office alternative - wps office

Frequently Asked Questions

What happens if the document has fewer than six pages left?

The macro saves the remaining pages in a final DOCX file; it does not require the total page count to be divisible by six.

Why does a split file have a different page count?

The new document may use different page settings or reflow content. Open each output file and compare its layout and content with the source, especially around section breaks and floating objects.

Where are the split files saved?

The macro saves them in the source document's local folder, using a timestamp and sequential number in each filename.

How do I fix VBA error 91?

Error 91 indicates that an object variable has not been set. In the VBA editor, check that each Document or Range variable is assigned with Set before it is used.

Can I run this macro in Word for the web?

No. Open the document in desktop Word to use the VBA editor and run the macro.