Home > Back-end >  If the text is shaded I want to change the text color to red and cancel the shadow
If the text is shaded I want to change the text color to red and cancel the shadow

Time:12-23

msWord: I want to change the text color of shadowed texts to red and remove the shadow.

I wrote the code below. Makes the shaded text color red. But I couldn't remove the shadow and the code doesn't stop, system crashes. Thank you for your help.

Sub Make_Highlighted_Text_Red()
    With Selection.Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .Text = ""
        .MatchWildcards = False
        .Forward = True
        .Wrap = wdFindContinue
        .Highlight = True
    Do
        .Execute
        Selection.Range.Font.ColorIndex = 6
    Loop
    End With
End Sub

CodePudding user response:

Thanks everyone. I solved my problem with the codes below.

      Sub No_Shadow_Font_Color()
      Dim fndColor As String
      Dim rplcColor As String
      Dim myDoc As Document
      Dim myRng As Range
      Application.ScreenUpdating = False
      Set myDoc = ActiveDocument
      fndColor = wdRed 'Attention Please write the shadow color you want to change here
      rplcColor = wdAuto
      With Selection
        .HomeKey Unit:=wdStory
        With Selection.Find
          .Highlight = True
          Do While .Execute
            If Selection.Range.HighlightColorIndex = fndColor Then
              Set myRng = Selection.Range
              myRng.HighlightColorIndex = rplcColor
              myRng.Font.ColorIndex = 6
              Selection.Collapse wdCollapseEnd
            End If
          Loop
        End With
      End With
    Application.ScreenUpdating = True
    Set myDoc = Nothing
    End Sub
  • Related