Replacing words with certain Color

Anonymous
2020-04-08T12:54:25+00:00

Is there a way I can add curled brackets to all words with a certain color in a word file.

For instance, This is my text

Sentence one .

Sentence two.

Sentence Three.

Sentence four

I want it to be

Sentence {one} .

Sentence {two}.

Sentence {Three}.

Sentence {four}

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
{count} votes
Answer accepted by question author
  1. Jay Freedman 205.9K Reputation points Volunteer Moderator
    2020-04-08T16:38:37+00:00

    You could use a sequence of steps like those given in the Answer by HansV in this thread, using your color instead of Bold and using brackets instead of quote marks. However, that would apply the same color to the brackets as to the found text.

    If that's acceptable, you can stop there. To make the brackets not have the same font color, though, you would need additional steps to find colored brackets (left and right separately) and replace them with brackets with the black or Automatic. That's a bit tedious, so you can use the following macro (see http://www.gmayor.com/installing_macro.htm if needed) to do it all in one click.

    Sub AddBrackets()

        Dim rg As Range

        Set rg = ActiveDocument.Range

        With rg.Find

            .Format = True

            .Font.ColorIndex = wdRed ' replace as needed

            .Replacement.Text = "{^&}"

            .Execute Replace:=wdReplaceAll

        End With

        Set rg = ActiveDocument.Range

        With rg.Find

            .Text = "{"

            .Format = True

            .Font.ColorIndex = wdRed ' replace as needed

            .Replacement.Font.ColorIndex = wdAuto

            .Replacement.Text = "^&"

            .Execute Replace:=wdReplaceAll

        End With

        Set rg = ActiveDocument.Range

        With rg.Find

            .Text = "}"

            .Format = True

            .Font.ColorIndex = wdRed ' replace as needed

            .Replacement.Font.ColorIndex = wdAuto

            .Replacement.Text = "^&"

            .Execute Replace:=wdReplaceAll

        End With

    End Sub

    2 people found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Anonymous
    2020-04-09T07:57:20+00:00

    Thank you so much for this answer.

    0 comments No comments