简体   繁体   中英

If the text is shaded I want to change the text color to red and cancel the shadow

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM