Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In VBA how do I restore keyboard shortcut to default?

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?

like image 244
Josh Avatar asked Aug 28 '12 14:08

Josh


1 Answers

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", "" 
like image 192
SeanC Avatar answered Nov 14 '22 23:11

SeanC