VBA shortcut keys

msvec

Board Regular
Joined
Feb 18, 2002
Messages
202
Anyone know how to assign these with other keys than CTRL or CTRL+SHIFT...say maybe with ALT...i'm running out. Maybe there's a way to assign these outside of Macro|Options ??

Thanks
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Yes, there is. You can use the Onkey method to specify all sorts of shortcut keys for your macros. The only downside is that you need to set them when your workbook opens, and you should probably reset them when your workbook closes e.g.

Place this code in the workbook code module (see the workbook modules section from here to see how to do that).

Private Sub Workbook_Open()
Application.OnKey "%z", "MyMacro"
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.OnKey "%z", ""
End Sub

The first procedure sets up alt-z to run the macro named MyMacro. The second procedure resets it when the workbook closes.

If you have a macro called MyMacro, it will be run when you press Alt-z. Look in the VBA help file for Onkey and you'll find a full description of what it can do.
 
Upvote 0

Forum statistics

Threads
1,221,706
Messages
6,161,406
Members
451,702
Latest member
Kc3475

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