53.4. How to Record a Macro

When it comes to macros, one of the very cool features of Microsoft products is the capability of recording a macro with a macro recorder without having any knowledge of programming. The macro recorder records whatever you do in an IDE and then generates all the necessary programming code for you to use it.

Visual Studio has a built-in macro recorder as well. Even though we can be almost sure that users of Visual Studio IDE are technical developers, this recorder is still helpful for two reasons:

  • It can help a developer build a macro in less time rather than spending his or her time on writing programming code.

  • With the macro recorder you can generate an initial code for your macro, then start developing your macro based on this existing code. This is a common technique among developers to save the time and energy it would take to write all the code.

Using the macro recorder is easy. You need to open the Visual Studio IDE, then navigate to Tools Macros Record TemporaryMacro or simply press Ctrl+Shift+R to start recording a macro. Then do whatever you like in the IDE such as opening items, windows, or menus, and many other common tasks.

When you open the macro recorder a window appears in the IDE to let you work with the macro recorder and pause, stop, cancel, or continue recording the macro (Figure 53-3).

Figure 53.3. Figure 53-3

After recording your macro, you can stop the recording process and then open the generated TemporaryMacro in the Macros IDE to see the code. You can also rename this macro to a more relevant name for your needs. This macro is recorded in a module named RecordingModule in the MyMacros project by default, but you can move it to other projects or rename the module.

For example, the following code shows a macro that simply opens a Task List window for view:

Option Strict Off
Option Explicit Off
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports System.Diagnostics

Public Module RecordingModule
    Sub TemporaryMacro()
        DTE.ExecuteCommand("View.TaskList")
    End Sub
End Module

You can see how the macro recorder converts your actions to Visual Basic programming code. This is very handy and helpful in saving you time while building macros.

Even though the macro recorder is an excellent tool, don't forget that it can't accomplish all professional tasks. A professional macro may need hand-written code to make full use of the Development Tools Extensibility (DTE).

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.188.10.1