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 

Word Ole: How to bold every searched text?

 
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: Sun Sep 17, 2006 8:11 am    Post subject: Word Ole: How to bold every searched text? Reply with quote



I thought this code would do that, but nothing happens:

R := WordDoc.Range;
Direction := wdCollapseStart;
R.Collapse(Direction);
SearchText := 'Marcio';
OleVariant(R).Find.Execute(SearchText, EmptyParam, True, EmptyParam,
EmptyParam, EmptyParam, EmptyParam, wdFindContinue,
EmptyParam, SearchText, wdReplaceAll);
R.Font.Bold := Integer(True);

Am I missing anything?
Thanks,
Marcio
Back to top
Chris Cheney
Guest





PostPosted: Sun Sep 17, 2006 2:40 pm    Post subject: Re: Word Ole: How to bold every searched text? Reply with quote



"Marcio Ehrlich" <marcioehrlich_at_ig.com.br> wrote in
news:450cd998 (AT) newsgroups (DOT) borland.com:

Quote:
I thought this code would do that, but nothing happens:

R := WordDoc.Range;
Direction := wdCollapseStart;
R.Collapse(Direction);

If the range is collapsed, it will contain no text, and so the SearchText
won't be found.

Quote:
SearchText := 'Marcio';
OleVariant(R).Find.Execute(SearchText, EmptyParam, True, EmptyParam,
EmptyParam, EmptyParam, EmptyParam, wdFindContinue,
EmptyParam, SearchText, wdReplaceAll);
R.Font.Bold := Integer(True);

Am I missing anything?
Thanks,
Marcio

--
For e-mail address, remove the XXs
Back to top
Deborah Pate (TeamB)
Guest





PostPosted: Sun Sep 17, 2006 4:16 pm    Post subject: Re: Word Ole: How to bold every searched text? Reply with quote



<<Marcio Ehrlich:
I thought this code would do that, but nothing happens:
Quote:


A ReplaceAll operation goes through the document changing things
until its search for the searchtext turns up nothing. That means
that the found range at the end of the operation will be empty.

You need to use the Find's built in capability to replace
formatting, like this:

var
R: Range;
VarR, Direction: OleVariant;
...
R := WordDoc.Range;
VarR := R;
VarR.Find.Replacement.ClearFormatting;
VarR.Find.Replacement.Font.Bold := msoTrue;
VarR.Find.Execute('Marcio', MatchWholeWord := True,
Format := True, Wrap := wdFindContinue,
Replace := wdReplaceAll);
VarR.Find.Replacement.ClearFormatting;

The calls to ClearFormatting aren't necessary here but save a lot
of agonizing in later searches. :)

--
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: Sun Sep 17, 2006 11:07 pm    Post subject: Re: Word Ole: How to bold every searched text? Reply with quote

I can never thank you enough, Ms.Pate!
Marcio

"Deborah Pate (TeamB)" <Debs (AT) djpate (DOT) freeserve.co.not-this-bit.uk> escreveu:
Quote:
You need to use the Find's built in capability to replace
formatting, like this:
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.