V
vonclausowitz
Hi All,
I use this macro in Word to hightlight certain words. Now I want to use
wildcards but it's not possible with the code that I have because it
will replace everything with the wildcards.
Example:
this code searches a txt file with the words to look for. If in the txt
file I place the word:
Ira? the code will scan my document and replace words like Iraq and
Iran with Ira?.
So what I want is that it leaves the word as it is and just highlights
it.
Sub ColorWords(ByVal strText As String, _
ByVal MyColor As Variant)
With ActiveDocument.Content.Find
.ClearFormatting
.MatchWholeWord = True
With .Replacement
.ClearFormatting
.Font.Color = MyColor
.Highlight = True 'highlight the text in yellow
End With
.Execute FindText:=strText, ReplaceWith:=strText, _
Format:=True, Replace:=wdReplaceAll
End With
End Sub
Regards
Marco
I use this macro in Word to hightlight certain words. Now I want to use
wildcards but it's not possible with the code that I have because it
will replace everything with the wildcards.
Example:
this code searches a txt file with the words to look for. If in the txt
file I place the word:
Ira? the code will scan my document and replace words like Iraq and
Iran with Ira?.
So what I want is that it leaves the word as it is and just highlights
it.
Sub ColorWords(ByVal strText As String, _
ByVal MyColor As Variant)
With ActiveDocument.Content.Find
.ClearFormatting
.MatchWholeWord = True
With .Replacement
.ClearFormatting
.Font.Color = MyColor
.Highlight = True 'highlight the text in yellow
End With
.Execute FindText:=strText, ReplaceWith:=strText, _
Format:=True, Replace:=wdReplaceAll
End With
End Sub
Regards
Marco