# [VBA] - changing color when clicking on shape working as a button



## cmcamilo (Dec 21, 2022)

Hello,

I have a bunch of rounded rectangle shapes that work as buttons (so they are not CommandButtons).
In the image attached they are blue, but I actually want them to be white and turn blue when clicked.
So:
when I click one button, this should turn blue and all the others remain white.
When I click another button, that one should turn blue, the previous blue should turn white and all the remaining should keep white.

Can you help me achieve this?
Thank you.

PS: is there a place where I can see a list of colors and the correspondent codes for VBA?


----------



## anand3dinesh (Dec 21, 2022)

cmcamilo said:


> Hello,
> 
> I have a bunch of rounded rectangle shapes that work as buttons (so they are not CommandButtons).
> In the image attached they are blue, but I actually want them to be white and turn blue when clicked.
> ...


this would help you,
below code will change the button colour to blue which you click
you can change RGB values to which colour you could like to change

Sub test()

Dim shpNAME As String

Call FILLallSHP

shpNAME = Sheets("Sheet1").Shapes(Application.Caller).Name
Sheets("Sheet1").Shapes(shpNAME).Fill.ForeColor.RGB = RGB(0, 112, 192)

End Sub






Sub FILLallSHP()

Dim shp As Shape

For Each shp In Sheets("Sheet1").Shapes
    shp.Fill.ForeColor.RGB = RGB(242, 242, 242)

Next shp

End Sub


----------



## cmcamilo (Dec 22, 2022)

anand3dinesh said:


> this would help you,
> below code will change the button colour to blue which you click
> you can change RGB values to which colour you could like to change
> 
> ...


Thank you so much. It worked perfectly!


----------

