I've seen a couple of old threads on this but I'm not sure I'm fully understanding especially since my previous macro worked fine until I made some changes and now I'm getting some odd results when using HeaderFooter.LinkToPrevious.

I'm creating a book with this macro. There are something like 80 individual Word documents that can be used in the book as chosen by the User using a checkbox list control. So the macro goes through the list and determines if the chapter is selected by the user and, if so, it goes to the end of the document, creates a section break (Next Page) and the does the following:

ActiveDocument.Sections.Last.Headers(wdHeaderFooterFirstPage).LinkToPrevious = False
ActiveDocument.Sections.Last.Headers(wdHeaderFooterPrimary).LinkToPrevious = False
ActiveDocument.Sections.Last.Footers(wdHeaderFooterFirstPage).LinkToPrevious = False
ActiveDocument.Sections.Last.Footers(wdHeaderFooterPrimary).LinkToPrevious = False
Then, the new chapter is inserted like so:
Selection.InsertFile FileName:=FileSourceName, Range:="", ConfirmConversions:=False, Link:=False, Attachment:=False
At this point, the new chapter's first page header is the same header as the previous chapter. I change the new chapter's header like so:
With ActiveDocument.Sections.Last.Headers(wdHeaderFooterFirstPage).Range
Set oRange = ActiveDocument.Sections.Last.Headers(wdHeaderFooterFirstPage).Range.Paragraphs.Last.Range
oRange.Collapse wdCollapseStart 'Isolate the range from the anchor
oRange.InsertAfter ChptrNm
oRange.Expand unit:=wdParagraph
'Formatting takes place here
End With
If I do the same book (identical chapter selections) it will fail exactly the same way. Sometimes the linktoprevious = false method works, sometimes it doesn't. Interestingly, the footer linktoprevious = false seems to work fine.

From the other threads it sounded like this can be a tricky thing as to the timing of turning off the link and referencing the Section/Header properly.

Anyone have an idea what could be going on? Thanks.