logo
search
VBA & Macro Problems

How to Split a Word Document into Two-Page PDFs with VBA

Anum MushtaqAnum Mushtaq Oct 22, 2026 868 views

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.

How to Split a Word Document into Two-Page PDFs with VBA
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 you start

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.

Solution 1Recommended

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.

1
Open the VBA Editor

Press Alt + F11 in your word processor to open the VBA Editor.

2
Locate the Export Loop

Find the existing PDF export loop in your macro code, typically starting with 'For I = xStart To xEnd'.

3
Modify the Loop Increment

Change the loop declaration to step by 2 by appending 'Step 2' to the line: 'For I = xStart To xEnd Step 2'.

4
Update Export Arguments

Update the PDF export command arguments within the loop so that the starting page is 'I' and the ending page is 'I + 1'.

5
Execute the Macro

Click Run or press F5 to execute the macro and generate your two-page PDF pairs in the designated output folder.

Customizing Page Counts: If you need a different number of pages per PDF, change the step value to that number (e.g., Step 3) and set the ending page parameter to I + (Step - 1).
Automate Documents with WPS Office

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. 1. Open Document: Launch WPS Writer and open the document containing your macro.
  2. 2. Access Developer Tools: Navigate to the 'Tools' tab and click on 'Developer' to access the VBA Editor.
  3. 3. Modify Code: Locate your macro script and update the loop to 'Step 2' as described in the solution.
  4. 4. Run Macro: Click 'Run' to execute the script and automatically generate your two-page PDF exports.
Full compatibility with Microsoft Word macro-enabled documents (.docm).Built-in VBA editor for writing and modifying custom macro scripts.Native support for exporting documents directly to PDF formats.Lightweight, fast, and feature-rich Office alternative.
microsoft office alternative - wps office

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.