The Macros IDE

 < Free Open Study > 



Running Existing Macros

As you develop in .NET, you will most likely develop a project and modules of macros. Additionally, you will notice that Visual Studio comes with sample macro projects. You should take time to examine the numerous macro commands in the Samples set of macros. You can learn how to do things in a macro and in an add-in that otherwise might be very elusive. I certainly appreciate the code samples not only in the Samples set, but also throughout the MSDN help system.

Next, you'll learn how to manipulate code in a code window before you examine the Macros IDE. Listing 8-4 shows a macro command for commenting a selected block of Visual Basic code.

Listing 8-4: Commenting Visual Basic Code with a Macro

start example
 Sub CommentVBCode()     Dim sel As TextSelection = DTE.ActiveDocument.Selection()     Dim stpt As EditPoint = sel.TopPoint.CreateEditPoint()     Dim endpt As TextPoint = sel.BottomPoint     Try         Do While (stpt.LessThan(endpt))             stpt.Insert(""')             stpt.LineDown()             stpt.StartOfLine()         Loop     Catch     End Try End Sub 
end example

To run the macro, first select a block of code in the code window. Next, display the Macro Explorer by clicking its icon. Finally, right-click the CommentVBCode macro command in the Explorer. Figure 8-7 shows the selected code just before it is commented by the macro.

click to expand
Figure 8-7: Code block before commenting

Next, click the Run menu option. You could double-click the command in the Macro Explorer to execute the command. Figure 8-8 shows the code block immediately after the macro has been run and has commented the code.

click to expand
Figure 8-8: Code block commented by the macro command



 < 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

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net