| < Free Open Study > |
|
Once you have created a macro that you expect to use often, you may want to assign a set of shortcut keys to it. This is a simple process. First, you must record and rename a macro. I have chosen to record a macro that will duplicate a selected block of code immediately following the selection. I often find that I need to duplicate a line of code or a block of code and then modify it slightly. The macro that I recorded is shown in Listing 8-3.
Listing 8-3: DuplicateSelectedLines Macro
Sub DuplicateSelectedLines() DTE.ActiveDocument.Selection.Copy() DTE.ActiveDocument.Selection.LineDown() DTE.ActiveDocument.Selection.LineUp() DTE.ActiveDocument.Selection.Paste() End Sub
To record the shortcut keys for this macro, go to the Tools menu and click Options. The Options dialog box will open. In the Environment folder, click Keyboard. In the Commands list box, find the desired macro and click it to select it. In this case, it is listed as Macros, MyMacros, Module1, DuplicateSelectedLines. In the Press Shortcut key(s) box, press Ctrl-Shift-A. In the Use New Shortcut Key in box, select TextEditor. Finally, click the Assign and OK buttons to save the shortcut keys.
| < Free Open Study > |
|