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

cmcamilo

New Member
Joined
Dec 19, 2022
Messages
11
Office Version
  1. 365
Platform
  1. Windows
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?
 

Attachments

  • Buttons.png
    Buttons.png
    10.5 KB · Views: 16

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
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?
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
 
Last edited:
Upvote 0
Solution
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
Thank you so much. It worked perfectly!
 
Upvote 0

Forum statistics

Threads
1,214,940
Messages
6,122,361
Members
449,080
Latest member
Armadillos

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top