Document Editing Problems

Copy a Word Header When Splitting a Document with VBA

Adam DavisAdam Davis Nov 20, 2026 868 views

Question details

Copy the original document's primary header into each file created by a Word VBA page-splitting macro.

Copy a Word Header When Splitting a Document with VBA
Product
Microsoft Word
Device & OS
not provided
Scenario
A VBA macro splits a Word document into separate documents, and each output document needs the source header.
Observed behavior
Each new document should contain the primary header from the first section of the original document.
Before you start

Open the macro that performs the split and identify its source document and newly created document variables. The example below uses docMultiple for the source and docSingle for each output document.

Solution 1Recommended

Copy the Primary Header Range into Each New Word Document

Use this approach when your macro already creates separate documents and you want to add the original first section's primary header to each one.

The header range is captured before the new documents are created. FormattedText transfers the header content and its formatting without using the clipboard.

This copies only the first section's primary header. If the source uses different first-page or even-page headers, those headers and their page setup options require separate handling.

1
Open the VBA procedure

In Word, open Developer > Visual Basic and find the procedure that splits the document. Make sure docMultiple refers to the original document.

2
Capture the source header

Near the beginning of the procedure, before the loop that creates output documents, add: Dim rngHeader As Range Set rngHeader = docMultiple.Sections(1).Headers(wdHeaderFooterPrimary).Range.Duplicate rngHeader.End = rngHeader.End - 1 This excludes the header's final paragraph mark.

3
Copy the header into each file

Inside the loop, after docSingle is created and the page content is pasted, add: docSingle.Sections(1).Headers(wdHeaderFooterPrimary).Range.FormattedText = rngHeader.FormattedText Place this line before the code that saves or closes docSingle.

4
Run and check the macro

Run the procedure from the VBA editor or Word's Developer > Macros dialog. Open the output files and check their headers and formatting.

Copy the Primary Header Range into Each New Word Document
Section-specific headers: If pages in the source document belong to sections with different headers, select the relevant source section for each output file instead of always using Sections(1).
Free Microsoft Office alternative

Edit Word Documents and Headers with WPS Writer

WPS Office is a free, lightweight alternative with a familiar interface for opening, editing, and saving Word documents. Use WPS Writer to manage document content and headers when moving between Office-compatible files; it does not fix or guarantee compatibility with a Microsoft Word VBA macro.

Edit document headers in WPS WriterOpen and save Microsoft Word DOCX and DOC filesUse a familiar document-editing interface for an easier transitionWork with a lightweight suite that includes free editing tools
microsoft office alternative - wps office

Frequently Asked Questions

Why exclude the final paragraph mark from the source header range?

Reducing rngHeader.End by one excludes the header range's final paragraph mark while retaining its content for transfer to the new header.

Where should I put the header-copying code?

Capture the source range before the document-creation loop. Inside the loop, assign its FormattedText to docSingle after creating the new document and before saving or closing it.

Will this copy a different first-page header?

No. wdHeaderFooterPrimary refers to the primary header. A different first-page header must be handled separately, along with the relevant page setup option.

What if each section has a different header?

The example uses docMultiple.Sections(1). For section-specific headers, identify the source section for each page and use that section's Headers(wdHeaderFooterPrimary).Range instead.