Valentin Feydel
Valentin Feydel

Reputation: 31

Change all the same RGB colors of different forms/text

How do I change a color that is applied to various forms (border or background) and text areas which are in groups?

For example, I have a group "BigBox1" with "icon1", "icon2", "text1" inside and a group "BigBox2" with "icon11", "icon22", "text11" inside.

These elements are all in the color RGB(153, 153, 255), "icon1" and "icon11" have their border in this color, "icons2" and "icon22" have their background in this color, "text1" and "text11" have their font in this color.

In my document, I also have other groups ("BigBox3", "BigBox4") with different colors but I would only like to change the color RGB(153, 153, 255) to RGB(50, 66, 115) without the need to select individually each element which currently has the color RGB(153, 153, 255).

I am looking for a macro that looks for a RGB color in a document (whenever it is - background, border, font) then change its RGB color to another one.

I tried this.

Sub changecolor ()
    With ActiveDocument.Range.Find.Font
    .Format.Font.Color = RGB(153, 153, 255)
    .Replacement.Font.Color = RGB(50, 66, 115)
    .Execute Replace:=wdReplaceAll
    End With
End Sub

Upvotes: 0

Views: 80

Answers (1)

Timothy Rylatt
Timothy Rylatt

Reputation: 7850

Your code isn't working because .Execute isn't a method of Font

Sub changecolor ()
  With ActiveDocument.Range.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Font.Color = RGB(153, 153, 255)
    .Replacement.Font.Color = RGB(50, 66, 115)
    .Format = True
    .Execute Replace:=wdReplaceAll
  End With
End Sub

To change the border and background colors of the shapes you will need to loop through every shape, and its group items, and check the existing color of each property.

Upvotes: 0

Related Questions