H
Hilmar Everts
I have a Word XP document with, for example, 3 words that are highlighted
brightgreen and 1 word that is highligted red. With the code below I want to
remove the brightgreen highlight and give the red highlight
DoubleStrikeThrough and Outline. Unfortunately the code keeps looping.
Somehow the formatting (highlight) triggers this because when I do something
similar with a normal text search, everything goes peachy. Can anyone help
fix this problem ?
Sub FindWithFormat()
Dim oStoryRange As Range
Dim oResult As Range
Set oStoryRange = ActiveDocument.StoryRanges(wdMainTextStory)
Do
Set oResult = oStoryRange.Duplicate
With oResult.Find
.ClearFormatting
.Replacement.ClearFormatting
.Highlight = True
.Font.StrikeThrough = False
.Font.DoubleStrikeThrough = False
.Font.Outline = False
.Forward = True
.Wrap = wdFindStop
If .Execute Then
If oResult.HighlightColorIndex = wdUndefined Or
wdNoHighlight Then
'\\ Do nothing
ElseIf oResult.HighlightColorIndex = wdBrightGreen Then
oResult.HighlightColorIndex = wdNoHighlight
Else
oResult.Font.DoubleStrikeThrough = True
oResult.Font.Outline = True
End If
End If
End With
Loop While oResult.Find.Found
End Sub
brightgreen and 1 word that is highligted red. With the code below I want to
remove the brightgreen highlight and give the red highlight
DoubleStrikeThrough and Outline. Unfortunately the code keeps looping.
Somehow the formatting (highlight) triggers this because when I do something
similar with a normal text search, everything goes peachy. Can anyone help
fix this problem ?
Sub FindWithFormat()
Dim oStoryRange As Range
Dim oResult As Range
Set oStoryRange = ActiveDocument.StoryRanges(wdMainTextStory)
Do
Set oResult = oStoryRange.Duplicate
With oResult.Find
.ClearFormatting
.Replacement.ClearFormatting
.Highlight = True
.Font.StrikeThrough = False
.Font.DoubleStrikeThrough = False
.Font.Outline = False
.Forward = True
.Wrap = wdFindStop
If .Execute Then
If oResult.HighlightColorIndex = wdUndefined Or
wdNoHighlight Then
'\\ Do nothing
ElseIf oResult.HighlightColorIndex = wdBrightGreen Then
oResult.HighlightColorIndex = wdNoHighlight
Else
oResult.Font.DoubleStrikeThrough = True
oResult.Font.Outline = True
End If
End If
End With
Loop While oResult.Find.Found
End Sub