logo
search
VBA & Macro Problems

How to Split a Word Document into Multiple Files Using VBA

Chanuka GeekiyanageChanuka Geekiyanage Oct 1, 2026 868 views

Question details

The user wants to separate a single Word document into multiple smaller documents based on repeated sections or headings using a VBA macro.

How to Split a Word Document into Multiple Files Using VBA
Product
Word
Device & OS
not provided
Scenario
Automating the process of extracting specific sections from a large document (e.g., starting with 'Data_Start') and saving each section as a new file in the original folder.
Observed behavior
Users need a macro to locate specific text, copy the range to a new file, and save it. During this process, users frequently encounter Run-time error 4608 (Value out of range) due to invalid range boundary calculations.
Before you start

Before running any macros, ensure you have saved a backup copy of your original document and verify that the recurring text marker (like 'Data_Start') is consistently formatted throughout the file.

Solution 1Recommended

Use a VBA Macro to Split and Save Document Sections

Create and execute a macro that loops through the document, finds specific text markers, selects the range up to the next marker, and saves the selection as a new document.

When splitting a document, the macro must accurately identify the start and end of each section. It copies the identified range, pastes it into a newly generated document, and saves it in the original file's directory with a sequential name.

1
Open the VBA Editor

Press ALT + F11 on your keyboard to open the Visual Basic for Applications (VBA) Editor in Word.

2
Insert a New Module

Click on 'Insert' in the top menu, then select 'Module' to create a blank workspace for your code.

3
Paste the Split Macro Code

Paste your VBA code that searches for your specific section delimiter (e.g., 'Data_Start'). Ensure the code accurately defines the start and end ranges for each section.

4
Validate Range Boundaries

Carefully review the lines handling the range end positions. Adjust logic like 'rng.End - 1' to ensure it does not attempt to reference a position outside the document's actual length.

5
Run the Macro

Press F5 or click the 'Run' button. Check the source folder to verify that the individual files have been created and saved correctly.

Use a VBA Macro to Split and Save Document Sections
Troubleshooting Run-time Error 4608: If you receive Run-time error 4608 'Value out of range', it means your code is trying to select text that doesn't exist. This usually happens at the very end of the document. Ensure your loop includes a condition to stop when it reaches the end of the file.
Automate with WPS Office

Easily Split and Manage Documents with WPS Writer

WPS Writer provides robust support for VBA macros, allowing you to run custom scripts to split large documents seamlessly while ensuring excellent compatibility with Microsoft Office files.

  1. 1. Download WPS Office: Install WPS Office and ensure you select the version that includes VBA support if required by your OS.
  2. 2. Open Your Document: Launch WPS Writer and open the large document you wish to split.
  3. 3. Access the Developer Tools: Navigate to the Developer tab on the ribbon and click on 'Macros' to open the VBA environment.
  4. 4. Run the Macro: Paste your document-splitting VBA script, click Run, and watch WPS Writer automatically separate your files.
Fully compatible with Microsoft Word .doc, .docx, and .docm formatsSupports VBA macros for advanced document automation and scriptingLightweight, fast, and completely free to useIntuitive tabbed interface makes it easy to review multiple split documents at once
microsoft office alternative - wps office

Frequently Asked Questions

Why do I get Run-time error 4608 when splitting my document with VBA?

Run-time error 4608 ('Value out of range') occurs when the VBA code tries to reference a position that doesn't exist in the document. This is common when using calculations like 'rng.End - 1' at the very end of a document. You must ensure your code properly detects the end of the file to prevent boundary errors.

Can I save the split documents with automated file names?

Yes, your macro can be programmed to use an incrementing number (e.g., Document_1.docx, Document_2.docx) or extract specific text from each section to automatically name and save the new files directly into the original document's folder.

Will splitting a document keep the original formatting?

Yes, as long as the VBA macro is written to copy the range and paste it keeping the source formatting, the new split documents will retain the fonts, margins, tables, and styles of the original document.