Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.
1 out of 3 rated this helpful - Rate this topic

Running VBA Code from Visio

You can run your Microsoft® Visual Basic® for Applications (VBA) code within the Visual Basic Editor to test and debug it during development. This section discusses several ways to run your code in the Visual Basic Editor. For details about debugging a VBA program, such as adding breakpoints, adding watch expressions, and stepping into and out of execution, see the Microsoft Visual Basic Help.

A user can run your finished macros in the Microsoft® Visio® user interface by choosing it from the Macros submenu on the Tools menu. A macro is a VBA procedure that takes no arguments. Procedures that take arguments will not appear on the Macros submenu.

Macros dialog box

Macros dialog box

  1. Name of the selected macro
  1. List of available macros and add-ons
  1. List of accessible projects, modules, and drawings

A program can also run in response to events or in other ways that you design. For details about running a program in response to events, see http://msdn.microsoft.com/en-us/library/office/aa201787(v=office.10).aspx Chapter 21, Handling Visio Events. For other ways to run a program, see http://msdn.microsoft.com/en-us/library/office/aa201811(v=office.10).aspx Chapter 26, Packaging a Visio Automation Solution.

To run a macro from the Visual Basic Editor

  1. On the Tools menu, click Macros.
  1. In the Macros list, select the macro you want and click Run.
    If the macro you want is not listed, make sure you've chosen the correct project, module, or drawing in the Macros In list. Private procedures do not appear in any menus or dialog boxes.

Or,

  1. In the Project Explorer, open the module that contains the macro.
  1. In the Code window, click to place the insertion point inside the macro.
  1. On the Run menu, click Run Sub/UserForm.
    The macro that contains the insertion point runs.

To run a macro from the Macros dialog box in Visio

  1. In Visio, on the Tools menu, point to Macros, and then click Macros.
  1. In the Macros list, select your program and click Run.

Note From a user's point of view, it doesn't matter if the program the user runs is an add-on or a macro, so the Visio application combines these programs in dialog boxes. For example, you can run an add-on or macro from the Macros dialog box or from the Macros submenu.

To provide a description of your macro that appears in the Macros dialog box

  1. In the Visual Basic Editor, open the Object Browser.
  1. In the Project/Library list, click the project that contains the macro.
  1. In the Classes list, click the module that contains the macro, then right-click the macro in the Members of list and click Properties.
  1. Enter a description in the Description box.

To run your macro from the Visio Macros submenu

  1. On the Tools menu, click Macros.
  1. On the Macros submenu, point to the project that contains your macros, and then click the macro you want to run.

The following illustration shows how a module might appear on the Visio Macros submenu, with its macros displayed on the module's submenu.

Visio Macros submenu

Visio Macros submenu

If you want your macros to appear on the Macros submenu, but not the module that contains your macros, name your module ShowInMenu. The ShowInMenu module does not appear on the Visio Macros submenu, but its macros do, as shown in the following illustration.

Macros submenu showing a macro from the ShowInMenu module

Macros submenu showing a macro from the ShowInMenu module

Show:
© 2014 Microsoft. All rights reserved.