Microsoft Office Tutorials and References
In Depth Information
RUN A MACRO FROM A SHORTCUT KEY
Figure 104. Y ou can change the shortcut key using this dialog.
Additional Details: You can temporarily assign a macro to a shortcut key by
using a macro. Perhaps you want to turn on a shortcut key during one section
of a process and turn it off later in the process. The following line of code
temporarily assigns the MoveDown procedure to Ctrl+m:
Application.OnKey Key:="^m", Procedure:="MoveDown"
To cancel this assignment and return Ctrl+m to its normal function, use:
To permanently change the shortcut key via code, use:
Application.MacroOptions Macro:="MoveDown", ShortcutKey:="m"
Additional Details: Excel stores the shortcut key in the code module, but it is
not visible in the Visual Basic editor. You have to export the module from VBA.
Follow these steps:
Right-click the module in the Project Explorer and choose Export File.
Save the ﬁ le in a place where you can ﬁ nd it later. Excel proposes a name
such as Module1.bas. You can use this name.
Open the .bas ﬁ le in Notepad.
You see an attribute near each module. The shortcut key is listed, followed by
/n14. So, in Figure 105, the g\n14 attribute means the macro is assigned to
Ctrl+g. The G\n14 attribute means the macro is assigned to Ctrl+Shift+G.