I am trying to insert a word document with this code:
Selection.InsertFile FileName:=myfile, Link:=False
It works fine with most documents, but when myfile have a section and uses
header/footer the header from myfile overwrites my origin header. I only want
the main body of myfile and not the header.
I use Word 2003.
Dave Lett - 08 Feb 2006 20:58 GMT
Hi,
You can use something like the following instead:
Dim myfile As String
Dim oDoc As Document
myfile = "C:\Test.doc"
Set oDoc = Documents.Open(FileName:=myfile, Visible:=False)
Selection.InsertAfter Text:=oDoc.Range.Text
oDoc.Close SaveChanges:=wdDoNotSaveChanges
Set oDoc = Nothing
If you want the formatting of the text in Test.doc to come across, then use
the following:
Dim myfile As String
Dim oDoc As Document
myfile = "H:\Documents\Test.doc"
Set oDoc = Documents.Open(FileName:=myfile, Visible:=False)
Selection.Range.FormattedText = oDoc.Range.FormattedText
oDoc.Close SaveChanges:=wdDoNotSaveChanges
Set oDoc = Nothing
HTH,
Dave
> I am trying to insert a word document with this code:
> Selection.InsertFile FileName:=myfile, Link:=False
[quoted text clipped - 4 lines]
>
> I use Word 2003.
Doug Robbins - Word MVP - 08 Feb 2006 21:16 GMT
See the article "How is it possible to copy an entire document into another
document without bringing across the header and footer?" at:
http://www.word.mvps.org/FAQs/Formatting/PasteWithoutSectionInfo.htm

Signature
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP
>I am trying to insert a word document with this code:
> Selection.InsertFile FileName:=myfile, Link:=False
[quoted text clipped - 5 lines]
>
> I use Word 2003.