Shortcut key to commandbutton
You need an accelerator
Private Sub UserForm_Initialize()
CommandButton1.Accelerator = "C"
'Set Accelerator key to COMMAND + C
End Sub
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
"Ranjit kurian" wrote:
I have developed a forms through excel VBA, and the forms contain text box,
option button, commandbutton etc....
I need a macro code to create shortcut key to my commandbutton and
optionalbutton, for example : if i have a commandbutton called as Cancel, the
"C" of the Cancel button should be underlined, so that the user when they
select Alt+C that particular commandbutton should be activated/action to be
performed.
|