Fix Word Macro Fails to Split Merged Document
Question details
The user is attempting to run a VBA macro to split a mail-merged Word document into individual files, but the macro either fails to run or creates fewer output documents than expected.

- Product
- Word
- Device & OS
- not provided
- Scenario
- Using a VBA macro to automate the splitting of a large merged document into separate files based on individual records or sections.
- Observed behavior
- The macro completes but produces missing output documents (e.g., 14 files instead of 16), or halts due to regular expression object declaration errors.
Create a backup copy of your original merged document before running or modifying any VBA code. Turn on hidden formatting marks in your document to visually confirm the structure.
Verify and Restore Missing Section Breaks
Ensure every record in the merged document is separated by a section break, as the macro relies on these breaks to determine where to split the files.
When a mail merge document is generated, the split macro counts the sections to determine how to divide the pages. If section breaks are accidentally deleted or missing from the source document, the macro will group multiple records together into a single file, resulting in fewer output documents.
Open the merged document in Word. Navigate to the Home tab and click the 'Show/Hide ¶' icon (or press Ctrl+*) to reveal hidden paragraph marks and section breaks.
Scroll through the document to verify that a 'Section Break (Next Page)' or continuous break exists at the end of every individual record.
If you find missing breaks, place your cursor at the end of the affected record, go to the Layout tab, click 'Breaks', and select 'Next Page' under Section Breaks.
Once the document has uniform sections matching the number of expected output files, run the splitting macro again on a fresh copy.

Correct Regular Expression Declarations in VBA
Fix execution failures caused by missing VBA references or incorrect VBScript.RegExp object declarations within the macro code.
Try WPS Office for Seamless Mail Merge and Document Management
If you frequently encounter VBA errors or macro limitations in Microsoft Word, WPS Office provides a highly compatible, lightweight, and user-friendly alternative. WPS Writer offers built-in Mail Merge features that are easy to configure, reducing the need for complex VBA scripting to manage your documents.

Frequently Asked Questions
Why did my Word macro only split half of my merged document?
This usually happens when structural section breaks in the middle of your document were accidentally deleted. The macro groups the unbroken pages as a single section, resulting in fewer output files than expected.
How do I enable RegExp in a Word VBA macro?
Open the VBA Editor by pressing Alt + F11, navigate to Tools > References, and check 'Microsoft VBScript Regular Expressions 5.5'. This allows your macro code to recognize and use the RegExp variable.
Can I split a mail merge document into separate files without using VBA?
Yes. Instead of using VBA, you can complete the mail merge, export the final document as a PDF, and then use a PDF editor (like WPS Office PDF tools) to split the document by pages or file size.
What does 'User-defined type not defined' mean in my split macro?
This compilation error means your VBA code uses early binding for an object (like VBScript.RegExp) but the corresponding reference library hasn't been enabled in the VBA Editor's Tools > References menu.




