vba to: Insert pagebreak at the END of a Word file; use insertFile to add another word file as a NEW section

I have a series of .docx word 'Section' files to add successively, via vba, to the end of a word file called Title_page.

Title page is a single Word page, and no header is required.
Each section file contains one or more word pages, including header text specific to the Section

Sub my_test has loops removed to simplify viewing: it successively adds .docx files for Sections 1 and 2 to the end of the Title_page
To be successful, the Title page file and the Section 1 file MUST end with a page break (which I added manually).

Question 1: how do I use vba to automate adding a pagebreak to the Title page and to each successive section file, before insertion?
Question 2: code by Greg Maxey (sub AddSectionAndKillLinkToPrevious) enables files to be added a SECTIONS.
This preserves separate header texts for separate sections. I am uncertain how to add those methods myTest().

Thanks in anticipation,
Kelvin

Sub my_Test()
    Dim wdApp As Word.Application
    Dim wd_title As Word.Document
    Dim Source_Path As String
 
    'this adds extra files behind the title page, PROVIDED each file ends with a page break
   
    Set wdApp = CreateObject("Word.Application")
        wdApp.Visible = True
    'source of wd files
    Source_Path = "D:\"
    'open file with title page
    Set wd_title = wdApp.Documents.Open(Source_Path & "TitlePage.docx")
    'add section 1
    wd_title.Bookmarks("\EndOfDoc").Range.InsertFile Filename:=Source_Path & "Section1.docx"
    'add section 2
    wd_title.Bookmarks("\EndOfDoc").Range.InsertFile Filename:=Source_Path & "Section2.docx"
End Sub

Failed experience:    the following puts the pagebreak at the top of the file, not the end:

Dim objSelection As Object
    Set objSelection = wdApp.Selection    
    objSelection.InsertBreak (wdPageBreak)

Question 2:
Greg Maxey provides code that adds each inserted file as a new section, thus allowing different sections to have different Header content.
http://gregmaxey.mvps.org/word_tip_pages/add_section_break_and_unlink_headers.html (code below)

Is this the best way, and how do I use these methods in the code above? In particular, I could not create the SELECTION obj below..

Option explicit
Dim i As Long
Dim j As Long
Dim oDoc As Word.Document

Sub AddSectionAndKillLinkToPrevious()
Dim myRng As Word.Range
  Set oDoc = ActiveDocument
  Selection.InsertBreak Type:=wdSectionBreakNextPage 'I CANNOT GET MY CODE TO CREATE A SELECTION OBJ like this
  'Get the index number of the added section
  i = oDoc.Range(0, Selection.Sections(1).Range.End).Sections.Count
  With oDoc.Sections(i)
    For j = 1 To 3
      .Headers(j).LinkToPrevious = False
      .Footers(j).LinkToPrevious = False
    Next j
  End With
  'Note: j provides the constant value to unlink all three header\footer types.
lbl_Exit: '??? 'perhaps remains of an error detection system?
    Exit Sub ???
End Sub
Kelvin4Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GrahamSkanRetiredCommented:
Not sure how you know where the Selection is. Try it like this:
    Set oDoc = ActiveDocument
    oDoc.Bookmarks("\EndOfDoc").Range.InsertBreak Type:=wdSectionBreakNextPage
    With oDoc.Sections.Last
        For j = 1 To 3
            .Headers(j).LinkToPrevious = False
            .Footers(j).LinkToPrevious = False
        Next j
    End With

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Kelvin4Author Commented:
Thank you - your answer was tested and it works as required:

 'open file with title page
    Set wd_title = wdApp.Documents.Open(Source_Path & "TitlePage.docx")
    ''''''
'follow with repeat loop of:
    wd_title.Bookmarks("\EndOfDoc").Range.InsertFile Filename:=Source_Path & "whichEverIsThe NextImportWdfile.docx"
    wd_title.Bookmarks("\EndOfDoc").Range.InsertBreak Type:=wdSectionBreakNextPage
    'Exit Sub
    With wd_title.Sections.Last
        For j = 1 To 3
            .Headers(j).LinkToPrevious = False
            .Footers(j).LinkToPrevious = False
        Next j
    End With
    ''''''
Each imported 'Section' maintains the Header Text that was typed manually in each Section file before InsertFile.
Each imported 'Section' maintains the quick Parts fileName of each Section file before InsertFile.
However, after wd_title has finished receiving InsertFiles, its header quickParts page and numPage apply not to the original files but to the concatenated whole wd_title. That is a small quibble for a much later day!

Thank you
Kelvin
0
Kelvin4Author Commented:
Thanks, once again for great and speedy help.
My detailed report on your answer (v affirmative) is in the body of the question.

Kelvin
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Word

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.