Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Set focus on command button

I have a command button on my worksheet and the code
"CommandButton1.SetFocus" gives the error message "Object doesn't
support this property or method". But the help shows SetFocus as one
of the methods for CommandButton. Why doesn't it work? I want to set
the focus so that the user can just press enter to click the command
button. Is this the correct approach?

TIA,
Derek
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default Set focus on command button

Hi Derek

ActiveSheet.CommandButton1.Activate
seem to do what you want. SetFocus is used on forms with a Tab order; you
can Tab between controls. Controls on a worksheet doesn't behave that way,
so I guess that might cause the problem.

It does btw not click on Enter. Space bar is the usual keypress for it. If
you need Enter you'd have to code it (at least in Excel 2000) like this :

Private Sub CommandButton1_Click()
MsgBox "Clicked !"
End Sub

Private Sub CommandButton1_KeyDown(ByVal _
KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = 13 Then Call CommandButton1_Click
End Sub

--
HTH. Best wishes Harald
Followup to newsgroup only please

"Derek Gadd" skrev i melding
om...
I have a command button on my worksheet and the code
"CommandButton1.SetFocus" gives the error message "Object doesn't
support this property or method". But the help shows SetFocus as one
of the methods for CommandButton. Why doesn't it work? I want to set
the focus so that the user can just press enter to click the command
button. Is this the correct approach?

TIA,
Derek



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Set focus on command button

Derek,

Worksheet commandbuttons don't understand the SetFocus method, so you can't
do that. You can, however, set the focus to the command button like so

ActiveSheet.CommandButton1.Activate

but this doesn't help you as it also doesn't have a Default (or Cancel)
property, so you cannot set it to respond to Enter (or Esc).

Sorry.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Derek Gadd" wrote in message
om...
I have a command button on my worksheet and the code
"CommandButton1.SetFocus" gives the error message "Object doesn't
support this property or method". But the help shows SetFocus as one
of the methods for CommandButton. Why doesn't it work? I want to set
the focus so that the user can just press enter to click the command
button. Is this the correct approach?

TIA,
Derek



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 AhmetDY Excel Discussion (Misc queries) 1 October 17th 07 11:36 AM
button focus billq Excel Programming 4 November 13th 03 02:09 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 02:52 PM.

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"