• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Assign shortcut key to a command button

VARGEESH

Member
Hi,


I wrote some code in a command button and it is working well.


However, every time i needs to click it by using mouse.


Can you please advise me how to set a shortcut key for the command button.


It would be more helpful instead of using mouse.


Thanks for your help in advance.


Regards,

Vargeesh
 
Hi, VARGEESH!


If the command button is a form control, right click on the shape, assign macro, and select the proper one. It it's an ActiveX control, toggle to design mode (Programmer tab, Controls group, Design Mode icon), then right button on the shape, view code, and a <name_of_the_control>_Click() procedure gets displayed: just copy and paste your code in there or type its sub name qualifiying it by the related module if it applies.


Regards!
 
@SirJB7

I think you read the question too quickly...


@Vargeesh

Assuming the button uses a macro that is no private, you can open the macro menu with Alt-F8, select the macro, click on option, and assign a keyboard shortcut.

If it's a private macro (like for an ActiveX control), you'll need to write another macro within the same module to call the private one, and then assign keyboard shortcut to that.

Example of calling a Private macro:

[pre]
Code:
Private Sub CommandButton1_Click()
'Private macro controlled by ActiveX control
MsgBox "hi"
End Sub

Sub Test()
'Public macro that calls private macro
'Assign this macro to shortcut key
CommandButton1_Click
End Sub
[/pre]
 
Hi SirJB7,


Thanks for your reply.


My command button is on the excel sheet and for that i want to set shortcut key.


Now i am using mouse to access the command button. I just wanna set a shortcut key for that.


Waiting for your valuable advice.


Thanks!
 
Hi, VARGEESH!

Sorry for the misread, Luke M's right. I didn't understand what you actually asked.

Regards!


@Luke M

Hi!

Thanks for the correction.

Regards!
 
Back
Top