shortcut accelerators

errtu

Board Regular
Joined
Sep 23, 2010
Messages
134
Is there anyway to enable the accelerators for the Command buttons (activex control) WITHOUT ALT or CONTROL or any of those keys? Meaning, instead of pressing Button1 with ALT+A, that it should be activated with only pressing A?

That would be soooo useful for me
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
See Help for the OnKey method.
 
Upvote 0
See Help for the OnKey method.

awesome, just what I needed. Is there anyway to isolate them so that the onkey will only work on one specific spreadsheet, and not the whole workbook?
 
Last edited:
Upvote 0
Either in the individual worksheet's module, or in ThisWorkbook module, the sheet activate/deactivate events could be used.
 
Upvote 0
Either in the individual worksheet's module, or in ThisWorkbook module, the sheet activate/deactivate events could be used.

mmmm... an example of this, please? so i can work it out from there?

say i have in ThisWorkbook:

Code:
Private Sub Workbook_Open()
Run "RunOnOpen"
End Sub

module RunOnOpen is:

Code:
Sub RunOnOpen()
Application.OnKey "B", "Button"
sub end

and button is:

Code:
Sub Button()
 Sheets("Hello").Select
End Sub

If I go to spreadsheet "Close", I don't want the whole "B" button procedure to happen (so it wont take me back to "Hello").
 
Upvote 0
Hi there,

I personally would not use Workbook_Open or _Close for this. Rather, use the workbook's activate and deactivate events. These run upon opening/closing anyways, and additionally, catch when the user flips between workbooks in the same instance.

A quick example:

In a Standard Module:

<font face=Courier New><SPAN style="color:#00007F">Option</SPAN> <SPAN style="color:#00007F">Explicit</SPAN><br>    <br><SPAN style="color:#00007F">Public</SPAN> <SPAN style="color:#00007F">Function</SPAN> ActivateKey()<br>    Application.OnKey "B", "Sheet2.CommandButton1_Click"<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Function</SPAN><br>    <br><SPAN style="color:#00007F">Public</SPAN> <SPAN style="color:#00007F">Function</SPAN> DeactivateKey()<br>    Application.OnKey "B"<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Function</SPAN></FONT>

In the Worksheet's Module:

<font face=Courier New><SPAN style="color:#00007F">Option</SPAN> <SPAN style="color:#00007F">Explicit</SPAN><br>    <br><SPAN style="color:#00007F">Sub</SPAN> CommandButton1_Click()<br>    Application.Goto Sheet1.Range("A10"), <SPAN style="color:#00007F">True</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br>    <br><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> Worksheet_Activate()<br>    <SPAN style="color:#00007F">Call</SPAN> ActivateKey<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br>    <br><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> Worksheet_Deactivate()<br>    <SPAN style="color:#00007F">Call</SPAN> DeactivateKey<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>

In ThisWorkbook Module:

<font face=Courier New><SPAN style="color:#00007F">Option</SPAN> <SPAN style="color:#00007F">Explicit</SPAN><br>    <br><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> Workbook_Activate()<br>    <br>    <SPAN style="color:#00007F">If</SPAN> TypeName(ActiveSheet) = "Worksheet" <SPAN style="color:#00007F">Then</SPAN><br>        <SPAN style="color:#00007F">If</SPAN> ActiveSheet.CodeName = "Sheet2" <SPAN style="color:#00007F">Then</SPAN><br>            <SPAN style="color:#00007F">Call</SPAN> ActivateKey<br>        <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br>    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br>    <br><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> Workbook_Deactivate()<br>    <SPAN style="color:#00007F">Call</SPAN> DeactivateKey<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>

Hope that helps,

Mark
 
Upvote 0
ACK! I forgot to mention that the OnKey is case sensitive.
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,285
Members
452,902
Latest member
Knuddeluff

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top