How to use vbscript to copy a header from one Word document to another
From: Marc B. Hankin (mbh2010_at_aol.com)
Date: 02/16/05
- Next message: Lynn: "Re: FileExists Method"
- Previous message: Csaba2000: "Re: ReDim + 2 Dimensional arrays = Errors!"
- Next in thread: y sakuda: "Re: How to use vbscript to copy a header from one Word document to another"
- Reply: y sakuda: "Re: How to use vbscript to copy a header from one Word document to another"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 16 Feb 2005 07:16:43 -0800
I'm having trouble figuring out how to use vbscript to copy a header from
one Word document to another.
The code below generates an error message telling me that the requested
object doesn't
exist i.e., the error is produced by this line:
Set objSourcRange =
objSourcDoc.Sections(1).Headers(wdHeaderFooterPrimary).Range.text
However, the document does have two sections, and each section does have a
header. So, I'm stumped.
Any suggestions (preferably with explanation, or a clue where I can learn
what I'm doing wrong, etc.)
would be much appreciated.
Thanks, marceepoo
Here's the code:
Dim sSourcDocFulnam, sTargetDocFulnam
sSourcDocFulnam = "C:\Apps\test.speedText.doc.dot"
sTargetDocFulnam = "C:\Apps\New Microsoft Word Document.doc"
'
Set objWord = CreateObject("Word.Application")
'
Set objSourcDoc = objWord.Documents.Open(sSourcDocFulnam)
Set objSourcRange =
objSourcDoc.Sections(1).Headers(wdHeaderFooterPrimary).Range.text
'
Set objTargetDoc = objWord.Documents.Open(sTargetDocFulnam)
Set objTargetRange =
objTargetDoc.Sections(1).Headers(wdHeaderFooterPrimary).Range.text
'
objTargetRange = objSourcRange
- Next message: Lynn: "Re: FileExists Method"
- Previous message: Csaba2000: "Re: ReDim + 2 Dimensional arrays = Errors!"
- Next in thread: y sakuda: "Re: How to use vbscript to copy a header from one Word document to another"
- Reply: y sakuda: "Re: How to use vbscript to copy a header from one Word document to another"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|
|