Find all instances of yellow text and change the font color to red

I need a vba macro that searches for all text that has a font color like yellow in an MS Word 2007 document and changes it to red. Yellow will not appear in printouts. If you select and change manually, it will take several hours.

+3
source share
3 answers

Following stakxs Word 97 solution, heres works in Word 2010:

  • Open the Find and Replace dialog (for example, Ctrl-H)
  • Click in the Find What field.
  • Drop-down format, font, select the color of the font to be found, OK.
  • Click in the Replace With box.
  • Drop-down format, font, select a color so that it ends, OK.
  • , : " " " " .
  • / / .

:

  • . " ", " " , " ".
+7

. Word 97, , Word 2007 :

  • " ".
  • , : ( ).
  • (?).
  • ( ).
  • \1.
  • ( ).
  • .

2, 3 5 ( ) .

VBA, , .

+5
Sub ChangeColorWithReplace()   
    Selection.Find.ClearFormatting
    Selection.Find.Font.Color = wdColorYellow
    Selection.Find.Replacement.ClearFormatting
    Selection.Find.Replacement.Font.Color = wdColorRed
    With Selection.Find
        .Text = ""
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchKashida = False
        .MatchDiacritics = False
        .MatchAlefHamza = False
        .MatchControl = False
        .MatchByte = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
End Sub

, . , , :

Sub ChangeFontColorByCharacter()
    Application.ScreenUpdating = False
    Dim d As Document: Set d = ActiveDocument
    For i = 1 To d.Characters.Count
        If d.Characters(i).Font.TextColor.RGB = RGB(255, 255, 0) Then
            d.Characters(i).Font.TextColor.RGB = RGB(255, 0, 0)
            DoEvents
        End If
    Next
    Application.ScreenUpdating = True
End Sub
+3

Source: https://habr.com/ru/post/1764296/


All Articles