How to Split a Word Document into Multiple Files Using VBA
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.

- 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 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.
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.
Press ALT + F11 on your keyboard to open the Visual Basic for Applications (VBA) Editor in Word.
Click on 'Insert' in the top menu, then select 'Module' to create a blank workspace for your 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.
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.
Press F5 or click the 'Run' button. Check the source folder to verify that the individual files have been created and saved correctly.

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. Download WPS Office: Install WPS Office and ensure you select the version that includes VBA support if required by your OS.
- 2. Open Your Document: Launch WPS Writer and open the large document you wish to split.
- 3. Access the Developer Tools: Navigate to the Developer tab on the ribbon and click on 'Macros' to open the VBA environment.
- 4. Run the Macro: Paste your document-splitting VBA script, click Run, and watch WPS Writer automatically separate your files.

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.




