The following code is attached on a Userform.
On the UF, 3 color option buttons are available for choice, named respectively oRed, oGreen, oYellow.
Once user click on any option button, a click even is triggered with the following sub-procedure.
Basically the code aims to remove any one of the highlighted background colors, as selected by user.
However, it does not work well and I am confused which part goes wrong.
This is my another attempt in learning Word VBA. Hope also to receive some advice on improving the coding.
Thanks very much!
Unload MeSub Dehighlight() Dim rng As Range Set rng = Selection.Range With Selection.Range '------------------- ' f .Find.ClearFormatting .Find.Highlight = True '------------------- While .Find.Execute(Wrap:=wdFindContinue, Forward:=True) And .InRange(rng) If .HighlightColorIndex = Switch(oRed.Value = True, wdRed, _ oYellow.Value = True, wdYellow, _ oGreen.Value = True, wdGreen) Then .HighlightColorIndex = wdNoHighlight End If Wend End With
End Sub



Reply With Quote
