Toggling a Command Button

T

T. Jenkins

I'm trying to setup a command button toggles between two captions, and
performs a different routine depending on the caption when pushed. I found
the routine below in the help, and this would appear to be perfect. However,
when it attempts to execute the caption change, I get an "object required"
error.

Using Excel 2003 with Win XP.

Any suggestions?

Todd

Private Sub CommandButton1_Click ()
If CommandButton1.Caption = "OK" Then
'Check caption, then change it.
CommandButton1.Caption = "Clicked"
CommandButton1.Accelerator = "C"
'Set Accelerator key to COMMAND + C
Else
CommandButton1.Caption = "OK"
CommandButton1.Accelerator = "O"
'Set Accelerator key to COMMAND + O
End If
End Sub
 
J

Jim Cone

Todd,

It works for me in XL2002.
The code should be in the module behind the sheet with
the button on it.
The button should be from the Control Toolbox not the Forms toolbar.
It will only work if the button you add is the first one added
to the sheet. It will have the name CommandButton1, subsequent
buttons added will have a different suffix number.

Regards,
Jim Cone
San Francisco, USA
 
T

T. Jenkins

Ok, thanks. I couldn't see a reason why it shouldn't work, but I'll check a
couple of the things you mention.

Todd
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top