About Automation (Visio)
Last modified: June 20, 2011
Applies to: Office 2013 | Visio 2013
You can write programs to control Microsoft Visio in Microsoft Visual Basic for Applications (VBA), Microsoft Visual Basic, Microsoft Visual C++, any of the Microsoft Visual Studio .NET languages, or in 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.
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 Blank Page on the Insert tab.
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.
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: In the Code group on the Developer tab, click Macros.