
Here’s a slight modification using Sleep to place a 1/4 second pause between the button down and button up commands: Simulate Button Click with Sleepĭeclare Sub Sleep Lib "kernel32" ( ByVal dwMilliseconds As Long ) Sub SimulateButtonClick2 () Dim vTopType As Variant Dim iTopInset As Integer Dim iTopDepth As Integer 'Record original button properties With ActiveSheet. Likewise, if you want your simulation to last longer, you can add the Sleep command before the “Button Up” code. I chose to use 3D beveling, but you can also use shadows to give a similar illusion. Like usual, there’s more than one way to make a button look like it’s been pressed.
#EXCEL VBA ON OFF BUTTON CODE#
The beauty of this macro is you can assign it to all your shapes! The Application.Caller command feeds the name of the shape into the macro, so you don’t have to change the code for each shape. All that’s left to do is replace the 'Your Macro Here comment in the Button Click example with whatever you want your button to do when it’s clicked. There you have it! A simple indented flash is all you need to make your rectangular shape behave kind of like a command button when it is clicked. Here’s a GIF to show you what happens:ĭepending on your internet connection, you may have to wait several loops for all the frames of the GIF to load. Now, each time you click your rectangle, it’ll briefly look like it’s been clicked.

Insert a shape onto your worksheet and customize it however you like.

It’s loaded with VBA shortcuts to help you make your own macros like this one - we’ll send a copy, along with our Big Book of Excel VBA Macros, to your email address below.
#EXCEL VBA ON OFF BUTTON FREE#
If you have trouble understanding or remembering it, our free VBA Developer Kit can help. Make powerful macros with our free VBA Developer Kit BevelTopDepth = iTopDepth End With '- 'Your Macro Here '- End Sub ScreenUpdating = True 'Button Up - set back to original values With ActiveSheet. BevelTopDepth End With 'Button Down With ActiveSheet.

Sub SimulateButtonClick () Dim vTopType As Variant Dim iTopInset As Integer Dim iTopDepth As Integer 'Record original button properties With ActiveSheet.
