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.