Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / May 2008

Tip: Looking for answers? Try searching our database.

Shortcut key  to commandbutton

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ranjit kurian - 24 May 2008 07:57 GMT
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.
Joel - 24 May 2008 09:01 GMT
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

> I have developed a forms through excel VBA, and the forms contain text box,
> option button, commandbutton etc....
[quoted text clipped - 4 lines]
> select Alt+C that particular  commandbutton should be activated/action to be
> performed.
Ranjit kurian - 24 May 2008 18:31 GMT
Hi Joel

Thanks for the code, but actually my commandButton caption name is Cancel
and the button perform the below action

Private Sub CommandButton1_Click()
End
End Sub

so if i press Atl+C to my cancel button it should end the macro

> You need an accelerator
>
[quoted text clipped - 24 lines]
> > select Alt+C that particular  commandbutton should be activated/action to be
> > performed.
Norman Jones - 24 May 2008 10:15 GMT
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

>I have developed a forms through excel VBA, and the forms contain text box,
> option button, commandbutton etc....
[quoted text clipped - 6 lines]
> be
> performed.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.