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