How can you highlight same word through a Word document?

I

Inter2Land

This is something I found in Word 'help'. It'll change all
instances of what I find, but I have no luck finding the
syntax/command to highlight the hits rather than changing
them. Can you help me out?

With ActiveDocument.Content.Find
Set myRange = ActiveDocument.Content
myRange.Find.Execute FindText:="employer_lname",
ReplaceWith:=" EMPLOYER_LNAME", _
Replace:=wdReplaceAll
End With

Thanks!!!
 
J

Jonathan West

Inter2Land said:
This is something I found in Word 'help'. It'll change all
instances of what I find, but I have no luck finding the
syntax/command to highlight the hits rather than changing
them. Can you help me out?

With ActiveDocument.Content.Find
Set myRange = ActiveDocument.Content
myRange.Find.Execute FindText:="employer_lname",
ReplaceWith:=" EMPLOYER_LNAME", _
Replace:=wdReplaceAll
End With

Thanks!!!

Unfortunately not. Microsoft didn't made this feature programmable when it
was first introduced in Word 2002.
 
J

Jean-Guy Marcil

Bonjour,

Dans son message, < Inter2Land > écrivait :
In this message, < Inter2Land > wrote:

|| This is something I found in Word 'help'. It'll change all
|| instances of what I find, but I have no luck finding the
|| syntax/command to highlight the hits rather than changing
|| them. Can you help me out?
||
|| With ActiveDocument.Content.Find
|| Set myRange = ActiveDocument.Content
|| myRange.Find.Execute FindText:="employer_lname",
|| ReplaceWith:=" EMPLOYER_LNAME", _
|| Replace:=wdReplaceAll
|| End With
||

You asked about highlighting words, but the example you posted replaces
words...
Just in case, this first example replaces AND highlights, the one after just
highlights.

'_______________________________________
Dim MyRange As Range

Set MyRange = ActiveDocument.Range
With MyRange.Find
.ClearFormatting
.Forward = True
.Text = "employer_lname"
.Wrap = wdFindStop
.Replacement.Text = "EMPLOYER_LNAME"
Do While .Execute(Replace:=wdReplaceOne)
With MyRange
.HighlightColorIndex = wdYellow
.SetRange .End, ActiveDocument.Range.End
End With
Loop
End With

Set MyRange = Nothing
'_______________________________________


'_______________________________________
Dim MyRange As Range

Set MyRange = ActiveDocument.Range
With MyRange.Find
.ClearFormatting
.Forward = True
.Text = "employer_lname"
.Wrap = wdFindStop
Do While .Execute
With MyRange
.HighlightColorIndex = wdYellow
.SetRange .End, ActiveDocument.Range.End
End With
Loop
End With

Set MyRange = Nothing
'_______________________________________

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top