# restart page numbering for an inserted document

• ### Question

• Hi,

I am trying to insert word documents, and then add a section to restart page numbering for each newly inserted document.  However, the page numbers do not restart, and the first document has no page numbers at all:

m_WordApp.ActiveDocument.Repaginate()
'If Not fileArray.Contains(filepath) Then

'm_WordApp.Selection.InsertParagraphAfter()
m_WordApp.ActiveDocument.Repaginate()
m_WordApp.Selection.InsertBreak(Type:=WdBreakType.wdPageBreak)
m_WordApp.Selection.EndKey(Unit:=6)
m_WordApp.Selection.Collapse(Direction:=WdCollapseDirection.wdCollapseEnd)

The initial formatting is as follows:

Any help would be greatly appreciated

Thursday, August 8, 2013 4:21 PM

• Try this code on a test document and then you can fit in a looping mechanism. In addition to placing the page number in the footer you have to restart the numbering and give it a starting number. You also need to backup from the last paragraph mark in the destination document; otherwise the footers of the inserted document will overwrite the destination footer. You'll see I used a temporary bookmark for this. You might also want to add code that makes sure the headers are also unlinked.

Finally just an FYI, I did this on a Mac so that's why the path string looks different.

Sub InsertFilesBySection()
Dim doc As Word.Document, rng As Word.Range
Dim i As Long
Set doc = ActiveDocument

'loop the following code
Set rng = doc.Bookmarks("\endofdoc").Range
rng.InsertBreak Word.WdBreakType.wdSectionBreakNextPage

i = doc.Sections.Count