Microsoft Office Tutorials and References
In Depth Information
RUN A MACRO FROM A SHORTCUT KEY
Part
3
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:
Application.OnKey Key:="^m"
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:
1.
Right-click the module in the Project Explorer and choose Export File.
2.
Save the fi le in a place where you can fi nd it later. Excel proposes a name
such as Module1.bas. You can use this name.
3.
Open the .bas fi le in Notepad.
4.
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.
 
Search JabSto ::




Custom Search