Search notes:

Excel Object Model: Application.onKey

application.onKey` allows to programatically set a shortcut key to invoke a function.
call application.onKey("^q" , "ctrl_q" ) Map ctrl+q to the sub ctrl_q
call application.onKey("%a" , "alt_a" ) Map alt+a to the sub alt_a
call application.onKey("+s" , "shift_s") Map shift+s to the sub shift_s
call application.onKey("{F12}", "f_12" ) Map a function-key.
In order to disable an association, the second parameter must be omitted:
call application.onKey("^q")

No parameters

It's not possible to specify a parameter when assigning a procedure to a shortcut key. Trying to do that like so:
application.OnKey "^x", "someSub(""x"")"
results in the error message Cannot run the macro 'someSub("x")'. The macro may not be available in this workbook or all macros may be disabled.

Lifespan and scope of shortcut keys

The assigned short cut keys are stored with the application (not the workbook) until the Excel instance is shut down.
Because a shortcut is not associated with a Workbook, the same shortcut key cannot be assigned to a per-Workbook function at the same time.

See also

The vb_procData.vb_invoke_func function attribute which allows to associate a VBA function with a keyboard shortcut key (at least in Excel).
The application object.

Index