VBA & Macro Problems

Fix Word Macro Fails to Split Merged Document

Rana GarciaRana Garcia Nov 2, 2026 868 views

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.

How to Troubleshoot a Word Macro That Fails to Split a Merged Document
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.
Before you start

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.

Solution 1Recommended

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.

1
Show formatting marks

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.

2
Inspect document structure

Scroll through the document to verify that a 'Section Break (Next Page)' or continuous break exists at the end of every individual record.

3
Insert missing breaks

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.

4
Rerun the macro

Once the document has uniform sections matching the number of expected output files, run the splitting macro again on a fresh copy.

Verify and Restore Missing Section Breaks
Consistent Document Structure: The macro will only function correctly if every output document has the exact same number of sections. Ensure uniformity across all records.
Free Microsoft Office alternative

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.

Fully compatible with Microsoft Word (.docx, .doc) formats and existing Mail Merge templates.Lightweight installation with a familiar, tabbed user interface for seamless migration.Built-in PDF conversion and splitting tools to manage bulk documents without relying on external macros.Free to use, with a robust suite of tools for processing large sets of records easily.
microsoft office alternative - wps office

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.