Shape color toggling

Copper Contributor

Hello. I am new to VBA. And I am working on a project we’re I’m using a shape as a button . I’m trying to have the code change the fill and text color on a click and then back if clicked again. So the button would be able to change back and forth when clicked . I am having trouble with getting the button to change the colors back and forth . Does anyone have a good code for this ? 
 The shape is starting with with fill as white and texts color is RGB 120,190,32. When clicked Im trying to swap it where the fill becomes the color the text becomes white. Any help will be appreciated 

1 Reply

@Kai3313 

Assign this macro to the shape. You can add other code too of course.

Sub ClickMe()
    Dim shp As Shape
    Dim clr As Long
    Set shp = ActiveSheet.Shapes(Application.Caller)
    clr = shp.Fill.ForeColor.RGB
    shp.Fill.ForeColor.RGB = shp.TextFrame.Characters.Font.Color
    shp.TextFrame.Characters.Font.Color = clr
End Sub