vba concatenation of Word (.docx) 'source' documents into one masterWd.docx. How to include headers of original source documents?

I concatenate separate word docx (with header content) into wdDoc, then wdDoc is saved in wordFormatPdf.
Neither wdDoc nor the PDF display the header texts.

Extract of code:---------------------------------------------

Set wdDoc = wdApp.Documents.Add
Do Until sh.Cells(r, 1).value = ""    'rows with qualifying file names have sh.Cells(r, 1) <>"" 
        If Len(wdDoc.Range) > 0 Then
            wdDoc.Bookmarks("\EndOfDoc").Range.InsertBreak wdPageBreak
        End If
                                                ' sh.Cells(r, 2).value provides source wd file names:
        wdDoc.Bookmarks("\EndOfDoc").Range.InsertFile FileName:=Source_Path & sh.Cells(r, 2).value
        r = r + 1
Loop
                          'Source_Path = filePath
wdDoc.SaveAs Source_Path & "concat_wd_doc", wdFormatDocument
wdDoc.SaveAs Source_Path & help_PDF_FileName, wdFormatPDF
wdDoc.Close wdDoNotSaveChanges

End of code:-------------------------------------------------

The first page of wdDoc is intentionally blank, ie the first concatenated file appears at r=1

Headers for source documents contain two rows of text, including Word 'quick parts': fileName; Page; numPages
Neither the concat_wd_doc, nor the ultimate PDF file display the headers provided in the original source docx.

Thanks
Kelvin
Kelvin4Asked:
Who is Participating?
 
GrahamSkanRetiredCommented:
InsertFile takes the header from the target document and you have just created one with a blank header.
Remove this:
 If Len(wdDoc.Range) > 0 Then
            wdDoc.Bookmarks("\EndOfDoc").Range.InsertBreak wdPageBreak
  End If

Open in new window

 
and put this just before the saves
    wdDoc.Range(0, 0).InsertBreak wdPageBreak

Open in new window

0
 
Kelvin4Author Commented:
Graham, thanks for immediate help.

You have shed light and method, however, ...
you have also smoked out some further problems with my code, so I may be back to you, after I've cut the code down and identified the troublesome bits.

Kelvin
0
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.

All Courses

From novice to tech pro — start learning today.