This quick how-to snapshot shows you how to change shape color with VBA. For the purpose of this snapshot, the main focus is the VBA code.
How-to change shape color with VBA
So, in these snapshots, we will show you the worksheet and the code. Again, the main focal point is the VBA code.
To make this work, we just need a worksheet with a box and code to push the update.
Firstly, we have a worksheet that contains a box and a form button. We link the form button to the Change_Color macro. Now, you do not need to create the button. You can just run the macro from the Developer tab. But sometimes, we get kind of lazy.
Secondly, we need macro code to make the color change. Basically, once the user clicks on the button, the box will change to RGB color 70, 114, and 196. RGB is short for red, green, and blue. Thus, you mix those together to get a color. In our case, a bluish color.
If you are familiar with VBA, then you can change the RGB property to Hex or another color code.
Below is the code, which you can select.
ActiveSheet.Shapes.Range("Rectangle 1").Fill.ForeColor.RGB = RGB(70, 114, 196)
So, you may not need ActiveSheet at the beginning. However, we did not test it.
Running the macro
Follow these steps to change the color of the box.
- Change the color of the box
- Click the Change color button
That is all to it. Enjoy!
Here is some related information to this snapshot.