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 previous versions of Visual Studio, with the exception of Visual C++, the only way to do this was to tediously perform the actions over and over again. But now, in Visual Studio .NET, 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 .NET Automation Object Model. For more information, see Creating Add-Ins and Wizards.
|To learn more about||See|
|Creating and recording macros.||Recording Macros|
|Various ways to run macros and pass parameters.||Running Macros|
|Troubleshooting macros and macro recording and running issues.||Macro Recording and Running Issues|
|How to edit an existing macro or manually create a new one.||Editing Macros|
|How to debug a macro.||Debugging Macros|
|Macro Explorer and its context menus.||Managing Macros|
|How to reference COM and .NET Framework components in macros.||Referencing COM and .NET Framework Components in Macros|
|The EnvironmentEvents template and the OnMacrosRuntimeReset event.||Macros and the EnvironmentEvents Project Item|
|Security and sharing issues with macros.||Macros Security and Sharing Issues|
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 .NET toolbar or in the Command window in Command mode. The specifics of this are covered in Running 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 Recording 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 .NET environment, but it is a separate environment designed solely for creating, editing, debugging, and running macros.
Now that you have a basic understanding of the tools used, start with Recording Macros to learn how to create a simple macro.
Note VS Macros do not currently support Windows Forms.