[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: 27

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
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,223,911
Messages
6,175,329
Members
452,635
Latest member
laura12345

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