 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Marcio Ehrlich Guest
|
Posted: Mon Sep 11, 2006 1:20 am Post subject: Replace text inside a Word Header |
|
|
The code below is not working, although it seems to me similar to several
examples I have found at the web to replace a string inside a first page
header.
var
FindText, ReplaceWith, Wrap, Replace: OleVariant;
HdrRange: Range;
begin
HdrRange :=
WordDoc.Sections.Item(1).Headers.Item(wdHeaderFooterPrimary).Range;
Wrap := wdFindContinue;
Replace := wdReplaceAll;
FindText := '...';
ReplaceWith := 'XXX';
HdrRange.Find.Execute(FindText, EmptyParam, EmptyParam,
EmptyParam, EmptyParam, EmptyParam, EmptyParam, Wrap,
EmptyParam, ReplaceWith, Replace);
end;
I'm feeling lost. What is wrong?
I using D7 with Word97 at the uses.
Thanks,
Marcio |
|
| Back to top |
|
 |
Oliver Townshend Guest
|
Posted: Mon Sep 11, 2006 5:07 am Post subject: Re: Replace text inside a Word Header |
|
|
| Quote: | The code below is not working, although it seems to me similar to several
examples I have found at the web to replace a string inside a first page
header.
|
I think word 97 has problems with this. Have you tried recording a macro
and seeing what 97 does?
The best way to do it might be to have a field (not a bookmark) in the
header, and update the value of the field.
Oliver Townshend |
|
| Back to top |
|
 |
Marcio Ehrlich Guest
|
Posted: Mon Sep 11, 2006 8:13 pm Post subject: Re: Replace text inside a Word Header |
|
|
Ok, not a bad idea. Guessed "title" should be a good field to populate the
header.
But how to change it programatically? Tried to record a macro but it did not
work.
Tried WordDoc.BuiltInDocumentProperties('Title') := 'XXX ' but it did not
work either...
No further information about document fields at the VB help.
Any hint?
Thanks,
Marcio
"Oliver Townshend" <oliveratzipdotcomdotau> escreveu :
| Quote: | The best way to do it might be to have a field (not a bookmark) in the
header, and update the value of the field. |
|
|
| Back to top |
|
 |
Marcio Ehrlich Guest
|
Posted: Mon Sep 11, 2006 8:29 pm Post subject: Re: Replace text inside a Word Header |
|
|
Found this but getting errror "Class does not have a default property":
const
wdPropertyTitle = $00000001;
begin
(...)
WordDoc.BuiltInDocumentProperties[wdPropertyTitle].Value := 'XXX'
[]s,
Marcio
"Marcio Ehrlich" <marcioehrlich_at_ig.com.br> escreveu:
| Quote: | Tried WordDoc.BuiltInDocumentProperties('Title') := 'XXX ' but it did not
work either... |
|
|
| Back to top |
|
 |
Deborah Pate (TeamB) Guest
|
Posted: Mon Sep 11, 2006 10:38 pm Post subject: Re: Replace text inside a Word Header |
|
|
<<Marcio Ehrlich:
Found this but getting errror "Class does not have a default
property":
Getting at the document properties is tricky in early binding.
Use a variant, like this:
var
VDoc: OleVariant;
...
VDoc := WordDoc.DefaultInterface; // if WordDoc is a component
{or}
VDoc := WordDoc; // if WordDoc is an interface
VDoc.BuiltInDocumentProperties[wdPropertyTitle].Value := 'XXX';
MS recommend using late binding (i.e. variants) for the
Find.Execute method as well, to work around some bugs.
--
Deborah Pate (TeamB) http://delphi-jedi.org
TeamB don't see posts sent via Google or ISPs
Use the real Borland server: newsgroups.borland.com
http://www.borland.com/newsgroups/genl_faqs.html |
|
| Back to top |
|
 |
Marcio Ehrlich Guest
|
Posted: Mon Sep 11, 2006 11:44 pm Post subject: Re: Replace text inside a Word Header |
|
|
Once again, thank you very much, Deborah.
Marcio
"Deborah Pate (TeamB)" <Debs (AT) djpate (DOT) freeserve.co.not-this-bit.uk> escreveu:
> VDoc.BuiltInDocumentProperties[wdPropertyTitle].Value := 'XXX'; |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|