How to Split a Word Document into Two-Page PDFs with VBA
Question details
The user needs to modify a Word VBA script to export a document into separate PDF files, where each PDF contains exactly two pages instead of one.

- Product
- Word
- Device & OS
- not provided
- Scenario
- Automating the extraction and export of a large document into smaller, paired-page PDF files using VBA macros.
- Observed behavior
- The user wants to achieve a grouped PDF export state (two pages per document) rather than the default one-page-per-PDF export.
Before modifying your VBA code, ensure you save a backup of your current document and macro script to prevent data loss in case of a syntax error.
Modify the VBA Loop Step for Two-Page Increments
Adjust your VBA 'For' loop to iterate in steps of two, allowing the export function to capture page 'I' and 'I + 1' simultaneously.
By default, a standard iteration loop moves one number at a time. Modifying the 'Step' keyword tells the macro to jump by a specific increment, enabling you to process pages in pairs.
Press Alt + F11 in your word processor to open the VBA Editor.
Find the existing PDF export loop in your macro code, typically starting with 'For I = xStart To xEnd'.
Change the loop declaration to step by 2 by appending 'Step 2' to the line: 'For I = xStart To xEnd Step 2'.
Update the PDF export command arguments within the loop so that the starting page is 'I' and the ending page is 'I + 1'.
Click Run or press F5 to execute the macro and generate your two-page PDF pairs in the designated output folder.
Use a Mail Merge Add-in for Merged Documents
If your document was originally created using Mail Merge, utilizing a dedicated add-in might be easier than writing custom VBA code.
Run Macros and Split Documents Effortlessly in WPS Writer
WPS Office provides robust support for VBA and Macros, allowing you to seamlessly run, edit, and troubleshoot code to automate your document workflows, including custom PDF exports.
- 1. Open Document: Launch WPS Writer and open the document containing your macro.
- 2. Access Developer Tools: Navigate to the 'Tools' tab and click on 'Developer' to access the VBA Editor.
- 3. Modify Code: Locate your macro script and update the loop to 'Step 2' as described in the solution.
- 4. Run Macro: Click 'Run' to execute the script and automatically generate your two-page PDF exports.

Frequently Asked Questions
Why does my VBA script export a blank page at the end of the document?
If your total document page count is an odd number, the final loop iteration (I + 1) will attempt to export a non-existent page. You can fix this by adding an 'If' condition in your VBA code to check if 'I + 1' exceeds the total page count before exporting.
How do I split a Word document into 5-page PDFs using VBA?
In your VBA loop, change the increment statement to 'Step 5'. Then, in the export parameters, set the starting page to 'I' and the ending page to 'I + 4'.
Can I use VBA in WPS Office to automate PDF exports?
Yes, specific versions of WPS Office fully support VBA macros. You can use the built-in VBA editor to write and execute scripts that automate repetitive tasks like exporting document pages to PDF format.




