Help with shortcut key code

W

will

I have created a bunch of macros and want to assign shortcut keys to
them using code instead of the tools option method since you have to
assign to a letter using that method. I have a bunch of subs that are
very basic and work when I use F5. To assign macros I created the
following code in the same module as the subs.

Public Sub Workbook_Open()
With Application
.OnKey key:="+^{$}", procedure:="fmtDollar"
.OnKey key:="+^{%}", procedure:="fmtPercent"
.OnKey key:="+^{!}", procedure:="fmtComma"
.OnKey key:="+^{~}", procedure:="fmtGeneral"
End With
End Sub

I cannot for the life of me figure out why the subs won't fire using
ctrl+shift+4, ctrl+shift+5 etc...

Any help is greatly appreciated.
 
G

Greg Wilson

I assume the use of the ":=" is a typo because the
compiler should have choked on this. To get numbers to
work leave them outside of the curly brackets:-

Sub OnKey()
Application.OnKey "^+4", "TestOnKey"
End Sub

Sub TestOnKey()
MsgBox "OnKey worked !!!"
End Sub

Regards,
Greg
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top