About Automation

Microsoft Visio Developer Reference

About Automation

You can write programs to control Microsoft Visio in Microsoft Visual Basic for Applications (VBA), Microsoft Visual Basic, C++, or any programming language that supports Automation.

A program can use Automation to incorporate Visio drawing and diagramming capabilities or to automate simple repetitive tasks in Visio. For example, a program might generate an organization chart from a list of names and positions or print all of the masters on a stencil.

Click to show or hide information.How a program using Automation controls Visio

A program controls Visio by accessing its objects and then using their properties, methods, and events.

  • Objects represent items you work with in the Visio application, such as documents, drawing pages, shapes, and cells containing formulas.
  • Properties are attributes that determine the appearance or behavior of objects. For example, a Shape object has a Name property, which represents the name of that shape.
  • Methods are actions provided by an object. For instance, a program can perform the Add method on a Page object. This is the same as adding a page to a document by clicking New Page on the Insert menu.
  • Events trigger code or entire programs. For example, an event can programmatically trigger code when a document is opened or trigger a program when a shape is double-clicked.

Click to show or hide information.The VBA programming environment in Visio

Microsoft Visio includes the Visual Basic for Applications (VBA) programming environment. To create, view, debug, and run programs in this environment, use the Visual Basic Editor:

  • Create VBA programs by inserting modules, class modules, and user forms into your VBA project and by writing code.
  • View VBA project items by choosing the project of an open Visio document in the Project Explorer. To view the Code window for individual items, open the appropriate folder in the Project Explorer and double-click the project item, or right-click the item and click View Code on the shortcut menu.
  • Debug VBA programs by adding breakpoints, including watch expressions, and stepping through code as it runs.
  • Run VBA macros in the following ways:

In the Visual Basic Editor: On the Run menu, click Run Macro.

In Visio: On the Tools menu, point to Macros, and then click Macros.