How to Duplicate a Page Based on a Number Using Word VBA Macro
Question details
The user needs to duplicate a specific page in a Word document a set number of times based on an input value or content control, without generating unwanted blank pages or incorrect formatting.

- Product
- Microsoft Word / WPS Writer
- Device & OS
- not provided
- Scenario
- Creating dynamic Word forms or templates where the number of completed page copies depends on a dynamically specified value.
- Observed behavior
- Manual duplication or standard copy-pasting often results in misplaced page breaks or extra blank pages. The goal is to automate clean page duplications using VBA.
Ensure that your Word document is saved as a Macro-Enabled Template (.dotm) or Macro-Enabled Document (.docm) to allow VBA scripts to run, and that the Developer tab is enabled in your ribbon.
Use a VBA Macro with the '\page' Bookmark and FormattedText
This method retrieves the first page via a hidden bookmark and copies it cleanly using FormattedText, avoiding the system clipboard and preventing misplaced page breaks.
By using a macro-enabled template, each new document begins with one clean page. Utilizing the built-in '\page' bookmark ensures you capture the exact layout of the page.
Instead of inserting manual page breaks, setting the first paragraph to 'Page break before' ensures each subsequent copied page formats perfectly.
Open your document and select the first paragraph of your template. Right-click, select 'Paragraph', navigate to the 'Line and Page Breaks' tab, and check the 'Page break before' option.
Press ALT + F11 to open the VBA Editor. Go to 'Insert' > 'Module' to create a new macro module.
Write a Sub procedure named 'AutoNew'. Use an InputBox within the macro to request and validate the number of copies from the user (e.g., from 1 to 50).
In your macro code, define the source range by capturing the hidden page bookmark: `Set rgSrc = ActiveDocument.Bookmarks("\page").Range`.
Create a loop for the requested number of copies. Inside the loop, collapse a destination range at the end of the document (`rgDest`) and copy the text without the clipboard by using the code: `rgDest.FormattedText = rgSrc.FormattedText`.

Automate Page Duplication with WPS Writer
WPS Office provides robust VBA and Macro support in its advanced versions, allowing you to seamlessly run Word macros, manage bookmarks, and automate document formatting without layout issues.
- 1. Enable Developer Tools: Open WPS Writer and navigate to the Developer tab in the top ribbon.
- 2. Access the VBA Editor: Click on 'Macros' or press ALT + F11 to launch the built-in Visual Basic Editor.
- 3. Run Your Duplication Macro: Paste your page duplication VBA code into a new module, save the document as a macro-enabled format, and run the script directly.

Frequently Asked Questions
Why am I getting extra blank pages when duplicating pages via VBA?
This usually happens when page breaks are copied along with paragraph marks. Using the 'Page break before' paragraph setting and copying via the `FormattedText` property in VBA helps prevent these unwanted blank pages.
How do I run this macro automatically when creating a new document?
Name your macro `AutoNew`. If the document is saved as a Macro-Enabled Template (.dotm), the `AutoNew` macro will trigger automatically each time a user creates a new document based on that template.
Can I save and run this VBA macro in standard .docx files?
No. Macros cannot be saved or executed in standard .docx files due to security restrictions. You must save your file as a Word Macro-Enabled Document (.docm) or a Macro-Enabled Template (.dotm).
What is the '\page' bookmark in Word?
The '\page' bookmark is a hidden, built-in system bookmark in Word that automatically represents the contents of the current page where the cursor is located, making it very useful for VBA selections.




