logo
search
VBA & Macro Problems

How to Duplicate a Page Based on a Number Using Word VBA Macro

Nimra MalikNimra Malik Sep 30, 2026 869 views

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.

How to Duplicate a Page Based on a Number Using Word VBA Macro
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.
Before you start

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.

Solution 1Recommended

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.

1
Configure the Initial Page Layout

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.

2
Open the Visual Basic Editor

Press ALT + F11 to open the VBA Editor. Go to 'Insert' > 'Module' to create a new macro module.

3
Create the AutoNew Macro and Request Input

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).

4
Set the Source Range

In your macro code, define the source range by capturing the hidden page bookmark: `Set rgSrc = ActiveDocument.Bookmarks("\page").Range`.

5
Duplicate the Content Using FormattedText

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`.

Use a VBA Macro with the '\page' Bookmark and FormattedText
Best Practice: Using FormattedText is highly recommended over standard Copy/Paste commands in VBA, as it operates faster and does not overwrite the user's system clipboard.
Efficient Document Automation

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. 1. Enable Developer Tools: Open WPS Writer and navigate to the Developer tab in the top ribbon.
  2. 2. Access the VBA Editor: Click on 'Macros' or press ALT + F11 to launch the built-in Visual Basic Editor.
  3. 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.
Fully compatible with Microsoft Word VBA macros and .docm/.dotm formats.Easily manage bookmarks, page breaks, and document automation with a familiar interface.Lightweight software with powerful developer tools for executing complex scripts.
microsoft office alternative - wps office

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.