In my VBA Excel add-in, I allow the user to assign arbitrary keyboard shortcuts to my public macros. I allow them to change these shortcuts at runtime (really, they change a configuration file and then reload it). I use Application.OnKey
to do this.
If the user changes a shortcut at runtime, how can I restore any previous default definition for the old keyboard shortcut?
For example, if I have programmatically assigned ^S
to a macro, and then change it to ^E
, how can I restore ^S
to the original Excel "Save" behavior?
To return a key defined through OnKey
to its default, define it with no procedure.
This sets CTRL+S to "SpecialPrintProc"
Application.OnKey "^S", "SpecialPrintProc"
This returns CTRL+S to its normal meaning.
Application.OnKey "^S"
This disables CTRL+S.
Application.OnKey "^S", ""
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With