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 AddSectionAndKillLinkToPre
vious) 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,
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.Applica
wdApp.Visible = True
'source of wd files
Source_Path = "D:\"
'open file with title page
Set wd_title = wdApp.Documents.Open(Sourc
e_Path & "TitlePage.docx")
'add section 1
le Filename:=Source_Path & "Section1.docx"
'add section 2
le Filename:=Source_Path & "Section2.docx"
Failed experience: the following puts the pagebreak at the top of the file, not the end:
Dim objSelection As Object
Set objSelection = wdApp.Selection
Greg Maxey provides code that adds each inserted file as a new section, thus allowing different sections to have different Header content.
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..
Dim i As Long
Dim j As Long
Dim oDoc As Word.Document
Dim myRng As Word.Range
Set oDoc = ActiveDocument
ge '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).Rang
For j = 1 To 3
'Note: j provides the constant value to unlink all three header\footer types.
lbl_Exit: '??? 'perhaps remains of an error detection system?
Exit Sub ???