View Single Post
 
Old 01-10-2018, 09:45 AM
slaycock slaycock is offline Windows 7 64bit Office 2016
Expert
 
Join Date: Sep 2013
Posts: 255
slaycock is on a distinguished road
Default

There must be more code that that because what you supplied won't run on its own.

You also need to be a little clearer regarding where the section breaks are located.

Do you insert a section break before you insert a document?

When you insert text from another document the cursor ends up at the end of the inserted text so if you want to set page numbering of the section at the start of the inserted text to 1 you will need to save the location of the cursor before you insert the file. You may also find that you don't actually get page 1 where you think it should go if the text before the section break is too long.

The code below demonstrates how to change the page number of the section where the file is inserted to 1(ish - due to the caveats above).

If the file starts with a section break then the code below will need to be modified to move the insertion point into the first section of the inserted text.

Code:
Sub test()
Dim insertion_point_before_insertion As Word.range

    Set insertion_point_before_insertion = Selection.range.Duplicate
    Selection.InsertFile FileName:="test.docx", range:="", ConfirmConversions:=True, Link:=False, Attachment:=False
    
    insertion_point_before_insertion.Select
    With Selection.HeaderFooter.PageNumbers
        .StartingNumber = 1
        .RestartNumberingAtSection = True
    End With

End Sub
Reply With Quote