Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
command button add another command | Excel Discussion (Misc queries) | |||
Command button | Excel Discussion (Misc queries) | |||
button focus | Excel Programming | |||
Command Button vs Control Button | Excel Programming | |||
Command Button vs Form Button | Excel Programming |