Close button on form

  • Thread starter Thread starter Sandy
  • Start date Start date
S

Sandy

I have a form which opens when excel opens

If Sheets("SearchRoundsData").Range("B2").Value = 1 Then
frmWelcome.Hide
Else
frmWelcome.Show
End If

On the form there is a close button "CommandButton1". Is it possible to give
this button focus so that the user can use the Enter keyboard key rather
than having to click with the mouse?

Thanks
Sandy
 
Hi Sandy

If you want CommandButton1 to have focus as the userform is shown, right
click on the userform, select tab order, bring CommandButton1 to the top.

Regards,
Per
 
As a user, I'm more used to using the Escape key to do the same as the Cancel
key and the Enter key to the same as the "ok" key.

You can accomplish this in your userform_initialize procedure with code like:

With Me.CommandButton1
.Caption = "Cancel"
.Cancel = True
'.Enabled = True
End With

With Me.CommandButton2
.Caption = "Ok"
.Default = True
'.Enabled = False
End With

If you really want to close the userform by hitting enter, you can use .default
= true on that commandbutton. (only one commandbutton can have those
properties.)
 
Back
Top