Shape color toggling

%3CLINGO-SUB%20id%3D%22lingo-sub-3324716%22%20slang%3D%22en-US%22%3EShape%20color%20toggling%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3324716%22%20slang%3D%22en-US%22%3E%3CP%3EHello.%20I%20am%20new%20to%20VBA.%20And%20I%20am%20working%20on%20a%20project%20we%E2%80%99re%20I%E2%80%99m%20using%20a%20shape%20as%20a%20button%20.%20I%E2%80%99m%20trying%20to%20have%20the%20code%20change%20the%20fill%20and%20text%20color%20on%20a%20click%20and%20then%20back%20if%20clicked%20again.%20So%20the%20button%20would%20be%20able%20to%20change%20back%20and%20forth%20when%20clicked%20.%20I%20am%20having%20trouble%20with%20getting%20the%20button%20to%20change%20the%20colors%20back%20and%20forth%20.%20Does%20anyone%20have%20a%20good%20code%20for%20this%20%3F%26nbsp%3B%3CBR%20%2F%3E%26nbsp%3BThe%20shape%20is%20starting%20with%20with%20fill%20as%20white%20and%20texts%20color%20is%20RGB%20120%2C190%2C32.%20When%20clicked%20Im%20trying%20to%20swap%20it%20where%20the%20fill%20becomes%20the%20color%20the%20text%20becomes%20white.%20Any%20help%20will%20be%20appreciated%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-3324716%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EDeveloper%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3326162%22%20slang%3D%22en-US%22%3ERe%3A%20Shape%20color%20toggling%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3326162%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1381998%22%20target%3D%22_blank%22%3E%40Kai3313%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAssign%20this%20macro%20to%20the%20shape.%20You%20can%20add%20other%20code%20too%20of%20course.%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-visual-basic%22%3E%3CCODE%3ESub%20ClickMe()%0A%20%20%20%20Dim%20shp%20As%20Shape%0A%20%20%20%20Dim%20clr%20As%20Long%0A%20%20%20%20Set%20shp%20%3D%20ActiveSheet.Shapes(Application.Caller)%0A%20%20%20%20clr%20%3D%20shp.Fill.ForeColor.RGB%0A%20%20%20%20shp.Fill.ForeColor.RGB%20%3D%20shp.TextFrame.Characters.Font.Color%0A%20%20%20%20shp.TextFrame.Characters.Font.Color%20%3D%20clr%0AEnd%20Sub%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E
Frequent Visitor

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