I have the following VBA code in a Word Template to insert a document at the cursor position when someone selects a button on the Word Ribbon (In this case it would be a document named 04-10A.docx). The code does this with no issues. The inserted document has a header and footer. The error occurs when the next document is inserted. The Header and Footer from the previous document is added to the 2nd document when it should not be. I thought this would not happen by using the SectionBreakNextPage but this is not working. Any ideas on how to fix this issue?
Public Sub 04_10A()
'
' Inserts at cursor location
Dim currentPosition As Range
Set currentPosition = Selection.Range 'pick up current cursor position
Selection.InsertBreak Type:=wdSectionBreakNextPage
With ActiveDocument.Bookmarks
.Add Range:=Selection.Range, Name:="FormInsert"
End With
'
Dim baseDoc As Document
Dim sfile As String
Set baseDoc = ActiveDocument
Set sdoc = Application.Documents.Open("X:\WorkTemplate\Forms\04-10A.docx")
Selection.WholeStory
Selection.Copy
ActiveWindow.Close savechanges:=wdDoNotSaveChanges
baseDoc.Activate
Set BMRange = ActiveDocument.Bookmarks("FormInsert").Range
BMRange.Application.Selection.PasteAndFormat (wdFormatOriginalFormatting)
'
End Sub
Public Sub 04_10A()
'
' Inserts at cursor location
Dim currentPosition As Range
Set currentPosition = Selection.Range 'pick up current cursor position
Selection.InsertBreak Type:=wdSectionBreakNextPage
With ActiveDocument.Bookmarks
.Add Range:=Selection.Range, Name:="FormInsert"
End With
'
Dim baseDoc As Document
Dim sfile As String
Set baseDoc = ActiveDocument
Set sdoc = Application.Documents.Open("X:\WorkTemplate\Forms\04-10A.docx")
Selection.WholeStory
Selection.Copy
ActiveWindow.Close savechanges:=wdDoNotSaveChanges
baseDoc.Activate
Set BMRange = ActiveDocument.Bookmarks("FormInsert").Range
BMRange.Application.Selection.PasteAndFormat (wdFormatOriginalFormatting)
'
End Sub