Sams Teach Yourself .Net in 21 Days
- Table of Contents
- Copyright
- About the Author
- About the Technical Editor
- Acknowledgments
- We Want to Hear from You
- Introduction
- Week 1: At a Glance
- Day 1. Introduction to the Microsoft .NET Framework
- Day 2. Introduction to Visual Studio .NET
- Day 3. Writing Windows Forms Applications
- Day 4. Deploying Windows Forms Applications
- Day 5. Writing ASP.NET Applications
- Day 6. Deploying ASP.NET Applications
- Day 7. Exceptions, Debugging, and Tracing
- Week 1. In Review
- Week 2: At a Glance
- Day 8. Core Language Concepts in Visual Basic .NET and C#
- Day 9. Using Namespaces in .NET
- Day 10. Accessing Data with ADO.NET
- Day 11. Understanding Visual Database Tools
- Day 12. Accessing XML in .NET
- Day 13. XML Web Services in .NET
- Day 14. Components and .NET
- Week 2. In Review
- Week 3: At a Glance
- Day 15. Writing International Applications
- Day 16. Using Macros in Visual Studio .NET
- Day 17. Automating Visual Studio .NET
- Day 18. Using Crystal Reports
- Day 19. Understanding Microsoft Application Center Test
- Day 20. Using Visual SourceSafe
- Day 21. Object Role Modeling with Visio
- Week 3. In Review
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.
Example 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.
Examining the Macro Recorder Code | Next Section

Account Sign In
View your cart