Running Existing Macros

 < Free Open Study > 

Assigning Shortcut Keys to a Macro

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

start example
 Sub DuplicateSelectedLines()     DTE.ActiveDocument.Selection.Copy()     DTE.ActiveDocument.Selection.LineDown()     DTE.ActiveDocument.Selection.LineUp()     DTE.ActiveDocument.Selection.Paste() End Sub 
end example

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 > 

Writing Add-Ins for Visual Studio  .NET
Writing Add-Ins for Visual Studio .NET
ISBN: 1590590260
EAN: 2147483647
Year: 2002
Pages: 172
Authors: Les Smith © 2008-2017.
If you may any questions please contact us: