Automating Repetitive Actions by Using Macros
While developing code in Visual Studio, you sometimes find yourself repeatedly performing a particular procedure or series of keystrokes. In Visual Studio, you can automate the process by using macros.
If you have used Microsoft Word or Microsoft Excel, you are probably familiar with macros. A macro is a set of instructions saved in a file (.Vsmacros) that can be executed later. You can either create the macro manually by typing the code in the Macros IDE, or you can have the environment record a macro for you automatically as you type and click. After a macro has been created, you can run it from Macro Explorer, the Find/Command box, or the Macros IDE, or you can use a keyboard shortcut to execute it.
Macros are also very helpful for learning about and programming against the Visual Studio Automation Object Model. For more information, see Creating Add-Ins and Wizards.
To learn more about
Creating and recording macros.
Various ways to run macros and pass parameters.
Troubleshooting macros and macro recording and running issues.
How to edit an existing macro or manually create a new one.
How to debug a macro.
Macro Explorer and its context menus.
How to reference COM and .NET Framework components in macros.
The EnvironmentEvents template and the OnMacrosRuntimeReset event.
Security and sharing issues with macros.
The following tools help you record, run, debug, and edit macros.
Macro Explorer This tool lists all macros available in the environment and is your main tool for viewing and executing macros. The top-most node contains macro projects, including the default project named MyMacros. Each macro project contains one or more modules, which in turn contain individual macro commands. Newly recorded macros appear as a command named TemporaryMacro, under a module called RecordingModule, which is under the project that is marked as the recording project. You can double-click a macro command to run it. To display Macro Explorer, press ALT+F8, or choose Macro Explorer on the Other Windows submenu on the View menu. For details about Macro Explorer, see Macro Explorer Window.
Find/Command box After you have recorded or created a macro, you can run it from the Find/Command box on the Visual Studio toolbar or in the Command window in Command mode. The specifics of this are covered in How to: Run Macros.
Recorder Toolbar When you initiate the recording of a macro, the Recorder Toolbar appears to help you with the process. It has buttons for starting, stopping, pausing, and canceling recording. Alternatively, you can use the Macros submenu on the Tools menu or keyboard shortcuts to control macro recording. For details about recording macros, see How to: Record Macros.
Macros IDE To edit or debug your existing macros, or to create new ones, use the Macros IDE. To view the Macros IDE, press ALT+F11 or choose Macros IDE on the Macros submenu on the Tools menu. The Macros IDE closely resembles the main Visual Studio environment, but it is a separate environment designed solely for creating, editing, debugging, and running macros.
VS Macros do not currently support Windows Forms.