I want to underline text and change the colour of the underline.
I am able to underline it but i cannot color it.
Here is my code.
With ActiveDocument.Range.find
.Text = errortxt
.MatchWholeWord = True
.Replacement.Font.Underline = wdUnderlineWavy
.Replacement.Font.underlinecolor = wdColorRed
.Execute replace:=wdReplaceAll
End With
if i use activedocument.range.find.font.underlinecolor = wdcolorred after
the with block it just changes the colour of all the underlined text in the
document
What am i doing wrong?
I don't know why that does not work. In fact, I couldn't even get it to work
in Word's usual Find and Replace box.
But, this works. The code needs to be optimized but will work.
Dim FoundCase As Boolean
Dim DocRange As Range
FoundCase = True
While FoundCase
Set DocRange = ActiveDocument.Range
With DocRange.Find
.text = errortxt
.Font.UnderLine = wdUnderlineNone
.Execute
If .Found Then
DocRange.Select
Selection.Font.UnderLine = wdUnderlineWavy
Selection.Font.UnderlineColor = wdColorRed
FoundCase = True
Else
FoundCase = False
End If
End With
Wend
> I want to underline text and change the colour of the underline.
> I am able to underline it but i cannot color it.
[quoted text clipped - 13 lines]
>
> What am i doing wrong?