Running VBA Code from Visio

3 4

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.

Figure 15-11.  <b>Macros</b> dialog box.(<b>A</b>) Name of the selected macro. (<b>B</b>) List of available macros and add-ons. (<b>C</b>) List of accessible projects, modules, and drawings.

Figure 15-11 Macros dialog box.(A) Name of the selected macro. (B) List of available macros and add-ons. (C) 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 Chapter 21, Handling Visio Events. For other ways to run a program, see Chapter 26, Packaging a Visio Automation Solution.

To run a macro from the Visual Basic Editor

  1. On the Tools menu, click Macros.
  2. In the Macros list, select the macro you want and click Run.
  3. 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.
  2. In the Code window, click to place the insertion point inside the macro.
  3. On the Run menu, click Run Sub/UserForm.
  4. 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.
  2. 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.
  2. In the Project/Library list, click the project that contains the macro.
  3. In the Classes list, click the module that contains the macro, then right-click the macro in the Members of list and click Properties.
  4. Enter a description in the Description box.

To run your macro from the Visio Macros submenu

  1. On the Tools menu, click Macros.
  2. 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.

Figure 15-12.  Visio <b>Macros</b> submenu.

Figure 15-12 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.

Figure 15-13.  <b>Macros</b> submenu showing a macro from the <b>ShowInMenu</b> module.

Figure 15-13 Macros submenu showing a macro from the ShowInMenu module.



Developing Microsoft Visio Solutions 2001
Developing Microsoft Visio Solutions (Pro-Documentation)
ISBN: 0735613532
EAN: 2147483647
Year: 2004
Pages: 180

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net