 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Marcio Ehrlich Guest
|
Posted: Sun Sep 17, 2006 8:11 am Post subject: Word Ole: How to bold every searched text? |
|
|
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
|
Posted: Sun Sep 17, 2006 2:40 pm Post subject: Re: Word Ole: How to bold every searched text? |
|
|
"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
|
Posted: Sun Sep 17, 2006 4:16 pm Post subject: Re: Word Ole: How to bold every searched text? |
|
|
<<Marcio Ehrlich:
I thought this code would do that, but nothing happens:
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
|
Posted: Sun Sep 17, 2006 11:07 pm Post subject: Re: Word Ole: How to bold every searched text? |
|
|
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 |
|
 |
|
|
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
|
|