Controlling Macros From Add-Ins

The Macros object in the Visual Studio .NET automation model gives you a measure of programmatic control over macros being recorded in the IDE. Using it, you can:

  • Pause or resume the macro recorder.
  • Write a line of code to the macro being recorded.
  • Determine whether the macro recorder is currently recording a macro.

You can also use the ExecuteCommand method to issue a command to the IDE, such as creating a new file.

Note   The Macros object members are not designed to be used within a macro, they must only be used within an Add-in.

Macros Example

The Visual Basic .NET example below demonstrates how to reference and use the various members of the Macros automation model.

Public Sub MacroTest()
   Dim objMac As Macros
   ' Determine if a macro is recording. If it is, pause it and add a line
   ' of code to it, and then let it resume recording.
   If objMac.IsRecording = True Then
      objMac.Pause()
      objMac.EmitMacroCode("MsgBox(""This was added by code."")")
      objMac.Resume()
   Else
      MsgBox("Macro is not recording.")
   End If
End Sub

See Also

Automating Repetitive Actions by Using Macros | Changing Window Characteristics | Creating and Controlling Environment Windows | Creating Add-Ins and Wizards | Creating an Add-In | Creating a Wizard | Automation and Extensibility Reference | Automation Object Model Chart