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 / November 2007

Tip: Looking for answers? Try searching our database.

How to copy text and header and footer from one document to another

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
michmill1973@yahoo.com.au - 22 Nov 2007 07:47 GMT
Hello,

I have a macro that opens a document, selects the text and then copies
it at the top of the active document, which works well to copy the
body text, but I can't work out how to also copy the header and
footer. The header contains an image and the footer text.

Below is what I currently have:

Dim strFileName As String
strFileName = "C:\Fax Header Source.doc"
Documents.Open (strFileName)

   Dim rngHeaderText As Range
   Set rngHeaderText = ActiveDocument.Content

       With rngHeaderText
           .Copy
       End With

ActiveDocument.Close (wdDoNotSaveChanges)

With ActiveDocument
   Selection.HomeKey Unit:=wdStory
End With

Selection.PasteAndFormat (wdPasteDefault)

Any advice on how to also copy the header and footer will be greatly
appreciated!

Regards

Michelle M
Helmut Weber - 22 Nov 2007 16:31 GMT
Hi Michelle,

you cannot copy a header or footer to another document,
only the contents of it, and you should be aware of
that pagesetup and sections in your target document
should be the same as in the source document.

You may record something like that in the source doc:

  ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
  Selection.WholeStory
  Selection.Copy
  ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument

open the target doc, do the same,
except copying but pasting.

There are other ways, but as this is the beginners' group...

HTH
--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP

Rate this thread:






 
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.