Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default Toggling a Command Button

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Toggling a Command Button

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. Jenkins" wrote in message
...
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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default Toggling a Command Button

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


"Jim Cone" wrote:

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. Jenkins" wrote in message
...
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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
command button add another command Wanna Learn Excel Discussion (Misc queries) 5 December 7th 08 11:42 PM
Command Button tom Excel Worksheet Functions 0 November 3rd 06 11:37 AM
Using a command button to add Chance Excel Discussion (Misc queries) 5 October 21st 05 08:08 PM
Command Button vs Control Button RGibson Excel Programming 1 October 14th 03 02:24 AM
Command Button vs Form Button T K Excel Programming 4 August 26th 03 07:26 PM


All times are GMT +1. The time now is 01:41 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"