Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / February 2006

Tip: Looking for answers? Try searching our database.

Insert document body, but not header

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Strømdahl - 08 Feb 2006 17:22 GMT
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.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.