Using the Macros IDE
The Macros IDE is the integrated development environment that Visual Studio .NET uses to manage macro projects and write macro code.To get to the Macros IDE, right-click on the TryCatchBlock macro in the Macro Explorer and select Edit. You should now be looking at something similar to Figure 16.6.
Figure 16.6. Editing a macro in the Macros IDE.

The Macros IDE is a separate IDE from Visual Studio .NET. However, it shares the same look and feel and has most of the same functionality. You can see that the MyMacros project is in the Solution Explorer, and RecordingModule is the default module name for the newly recorded macros. The code that was generated automatically is shown in Listing 16.2.
Listing 16.2 Visual Basic Code Generated by the Macro Recorder
Option Strict Off
Option Explicit Off
Imports EnvDTE
Imports System.Diagnostics
Public Module RecordingModule
Sub TryCatchBlock()
DTE.ActiveDocument.Selection.Text = "Try"
DTE.ActiveDocument.Selection.NewLine(2)
DTE.ActiveDocument.Selection.Text = _
"Catch ex as Exception" & Microsoft.VisualBasic.ControlChars.NewLine
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "messagebox."
DTE.ActiveDocument.Selection.DeleteLeft()
DTE.ActiveDocument.Selection.Text = ".Show(ex.Message)"
DTE.ActiveDocument.Selection.NewLine(2)
DTE.ActiveDocument.Selection.LineDown()
DTE.ActiveDocument.Selection.StartOfLine _
(vsStartOfLineOptions.vsStartOfLineOptionsFirstText)
DTE.ActiveDocument.Selection.LineUp()
DTE.ActiveDocument.Selection.Indent(2)
DTE.ActiveDocument.Selection.Text = "finally"
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.LineDown()
DTE.ActiveDocument.Selection.StartOfLine _
(vsStartOfLineOptions.vsStartOfLineOptionsFirstText)
DTE.ActiveDocument.Selection.Indent(2)
DTE.ActiveDocument.Selection.LineUp(False, 4)
DTE.ActiveDocument.Selection.LineDown(False, 2)
DTE.ActiveDocument.Selection.Indent()
DTE.ActiveDocument.Selection.LineDown()
DTE.ActiveDocument.Selection.LineUp()
DTE.ActiveDocument.Selection.EndOfLine(True)
DTE.ActiveDocument.Selection.Text = "Finally"
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.LineUp(False, 3)
DTE.ActiveDocument.Selection.CharRight(True)
DTE.ActiveDocument.Selection.Text = "M"
DTE.ActiveDocument.Selection.LineDown()
DTE.ActiveDocument.Selection.LineUp()
DTE.ActiveDocument.Selection.CharLeft()
DTE.ActiveDocument.Selection.EndOfLine(True)
DTE.ActiveDocument.Selection.Text _
= "Messagebox.Show(ex.Message)"
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.LineDown()
DTE.ActiveDocument.Selection.DeleteLeft()
DTE.ActiveDocument.Save()
End Sub
End Module
When you create a new macro project, the macros you create are simply the procedures added to the module in the project. In Listing 16.2, the MyMacros project contains a module named RecordingModule, and the TryCatchBlock macro is added as a subprocedure to the module.You can see by the code in Listing 16.2 that I had some typing problems when I recorded this macro. The macro recorder recorded every keystroke that I typed in the Code Editor. When you edit your macro, your code will look different depending on the keystrokes that you needed to enter the Try/Catch block. Because there was a lot of backspacing, deleting, and so on when I recorded my macro, it's in our best interest to fix it so that the code is only what we need. To fix the code, you must understand what's happening when the macros are being recorded.
• Table of Contents
• Index
Sams Teach Yourself Visual Studio® .NET 2003 in 21 Days
By
Jason Beres
Publisher
: Sams Publishing
Pub Date
: January 14, 2003
ISBN
: 0-672-32421-0
Pages
: 696
Sams Teach Yourself Visual Studio .NET in 21 Days will help developers that are new to application development and experienced developers understand how to use the .NET Framework and Visual Studio .NET to rapidly develop any type of computer application. The Visual Studio .NET development environment is the most comprehensive developer tool ever created, putting that together with the .NET Frameworks' Class Libraries, the developer has everything he or she needs to get up-to-speed on Microsoft's latest revolution in application development. This book will guide the developer through using the VS .NET IDE, the Visual Basic .NET and C# language, and the supporting tools available from Microsoft to create Windows and Web-based applications. The market is full of books that pretty much say the same thing, which is already available in the help files, the author of this book has written and deployed over a dozen successful applications using Visual Studio .NET and the .NET Framework. All of his expertise and experience is used to give you the most comprehensive title on using Visual Studio .NET.