Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


Header issue using VBA to insert Word documents into a Word Template

Header issue using VBA to insert Word documents into a Word Template

Header issue using VBA to insert Word documents into a Word Template

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")
ActiveWindow.Close savechanges:=wdDoNotSaveChanges
Set BMRange = ActiveDocument.Bookmarks("FormInsert").Range
BMRange.Application.Selection.PasteAndFormat (wdFormatOriginalFormatting)
End Sub

RE: Header issue using VBA to insert Word documents into a Word Template

You may want to re-post it in forum707: VBA Visual Basic for Applications (Microsoft) which is appropriate for your question.
When you do, please use TGML tags (just above the box where you type your question) to format your code. Use Preview button to make sure your post displays correctly.

Have fun.

---- Andy

There is a great need for a sarcasm font.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close