Table of contents
Collapse the table of content
Expand the table of content

About Automation (Visio)

office 365 dev account|Last Updated: 6/12/2017
1 Contributor

You can write programs to control Visio in Visual Basic for Applications (VBA), Visual Basic, Visual C++, any of the 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.

How a program uses automation to control 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 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.

The VBA programming environment in Visio

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.

© 2018 Microsoft