
204
|
Chapter 6, Speed Hacks
#51 Create a Macro
HACK
DTE.ActiveDocument.Selection.NewLine( )
DTE.ActiveDocument.Selection.Text = "This is a test"
DTE.ActiveDocument.Selection.NewLine( )
End Sub
End Module
The first line of the Sub called StartOfDocument( )will move the cursor to the
top of the document. The second line will create a new line. The third line of
this macro will insert the string “This is a test”, and the last line will create
another new line.
After you have written your macro in the Macro IDE, you can save the file
and then close the IDE. Your macro will now appear in the Macro Explorer
and can be run from the IDE.
Adding a Toolbar Button
Many macros will be useful in your daily life, so having to locate them
through the Macro Explorer each time can be inconvenient. Thankfully,
macros can be added to a toolbar.
To avoid cluttering existing toolbars, it is a good idea to create a new tool-
bar. First, select Customize from the View
➝ Toolbars menu. Click the New
button and specify the name for your new toolbar, as shown in Figure 6-14.
After creating the toolbar, a ghost of it will appear, as shown in the bottom
right of Figure 6-15. You can now select the Commands tab where you can
add your macro to the new toolbar.
In order to select the macro, you must first select the Macros category in the
Categories listbox. After scrolling past the sample macros (if they are
Figure 6-13. Adding a ...