BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Replace text inside a Word Header

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi OLE Automation
View previous topic :: View next topic  
Author Message
Marcio Ehrlich
Guest





PostPosted: Mon Sep 11, 2006 1:20 am    Post subject: Replace text inside a Word Header Reply with 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.

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





PostPosted: Mon Sep 11, 2006 5:07 am    Post subject: Re: Replace text inside a Word Header Reply with quote



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





PostPosted: Mon Sep 11, 2006 8:13 pm    Post subject: Re: Replace text inside a Word Header Reply with quote



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





PostPosted: Mon Sep 11, 2006 8:29 pm    Post subject: Re: Replace text inside a Word Header Reply with quote

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





PostPosted: Mon Sep 11, 2006 10:38 pm    Post subject: Re: Replace text inside a Word Header Reply with quote

<<Marcio Ehrlich:
Found this but getting errror "Class does not have a default
property":
Quote:


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





PostPosted: Mon Sep 11, 2006 11:44 pm    Post subject: Re: Replace text inside a Word Header Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi OLE Automation All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.