Macro Recording and Running Issues

The following is a list of issues you can encounter when recording and running macros in Visual Studio .NET.

Macro Recording Issues

When you record a macro, the environment tracks the elements you alter and the keys that you press and generates macro code based on that input. Not every UI element or event, however, can be recorded. Macro recording is limited to:

  • Text/Code editors, such as the Visual Studio .NET code editor.
  • Visual Studio .NET commands and menu items. By default, Visual Studio records command invocations by name if the commands themselves do not emit code against an automation model particular to the UI feature.
  • Common tree view tool windows, such as Solution Explorer.
  • The Add Item dialog box.
  • The Find and Replace dialog boxes.
  • General window events, such as activating or closing a window.

If, while recording a macro, you happen to manipulate an element of the environment that does not generate macro code, and did not go through a standard environment command — such as editing in an edit control in a dialog box — you will have a recording gap in your macro, and thus, the macro will not work as expected.

If this happens, you can manually edit the macro and in most cases, create the necessary code yourself. For details about how to do this, see Editing Macros.

Some commands are disabled while recording a macro, such as immediate search (ISearch), and the user model of the recording project and Recording module.

When you record a macro in the Code/Text editor, no mouse clicks or other mouse events are recorded. You must manually add such event code yourself after recording the macro, using such Visual Basic .NET functions as MouseMove, MouseDown, and MouseUp.

Note   VS Macros do not currently support Windows Forms.

Macro Running Issues

  • You cannot run a macro if its parent project cannot build, such as if another macro in the project contains errors.
  • Macros maintain the value of their variables between executions of the macro, but not between sessions of the integrated development environment (IDE). For example, if a particular macro increments a counter each time the macro is executed, that value is retained between invocations of the macro, but the value is lost if the Visual Studio .NET IDE is closed.
  • When you run a macro from Macro Explorer, the environment considers the last window that was opened immediately prior to opening Macro Explorer to be the last activated window, and the macro is run as if that window had focus. This prevents problems with Macro Explorer's window itself inadvertently getting the focus in your macro's operation.

Automating Repetitive Actions by Using Macros | Recording Macros | Editing Macros | Debugging Macros | Managing Macros | Referencing COM and .NET Framework Components in Macros | Macros and the EnvironmentEvents Project Item | Macros Security and Sharing Issues | Macro Explorer Window