Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 83
Default Shortcut key to commandbutton

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.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default 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.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 421
Default Shortcut key to commandbutton

Hi Ramit,

In addition to Joel's response, you can set the
CommanButton's Default property:

'===========
Private Sub UserForm_Initialize()
Me.CommandButton1.Default = True
End Sub
'<<==========

Then, hittting the Enter key will call the
Command_Button code.

Typically, you might set the default property
for a Cancel button on your form.


---
Regards.
Norman


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


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
shortcut has change or move so this shortcut can not open bakerstreet Excel Worksheet Functions 2 April 2nd 10 01:21 PM
commandbutton? Bobbykm Excel Programming 3 September 30th 07 01:13 AM
Macro Shortcut Key Conflicts with Application Shortcut Keys Jordan Hotzel Excel Programming 0 October 13th 06 06:39 AM
Macro Shortcut Key Conflicts with Application Shortcut Keys Jordan Hotzel Excel Programming 0 October 13th 06 06:39 AM
CommandButton Alvin Hansen[_2_] Excel Programming 3 August 16th 04 06:35 PM


All times are GMT +1. The time now is 09:38 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"