You can assign keyboard shortcuts to your macros by using the ‘shortcut’ keyword argument to the xl_macro
decorator, or by setting it in the SHORTCUTS section in the config.
Shortcuts should be one or more modifier key names (Ctrl, Shift or Alt) and a key, separated by the ‘+’ symbol. For example, ‘Ctrl+Shift+R’.
from pyxll import xl_macro, xlcAlert
@xl_macro(shortcut="Alt+F3")
def macro_with_shortcut():
xlcAlert("Alt+F3 pressed")
If a key combination is already in use by Excel it may not be possible to assign a macro to that combination.
In addition to letter, number and function keys, the following special keys may also be used (these are not case sensitive and cannot be used without a modifier key):
Backspace
Break
CapsLock
Clear
Delete
Down
End
Enter
Escape
Home
Insert
Left
NumLock
PgDn
PgUp
Right
ScrollLock
Tab