Calls a macro in a Microsoft Visual Basic for Applications (VBA) project.
RUNMACRO (** macroname ** [, ** projname_opt ** ])
||The name of the macro to call.
||The project that contains the macro.
If a project is specified, Microsoft Visio scans all open documents for the one containing projname_opt and calls macroname in that project. If projname_opt is omitted or null (""), macroname is assumed to be in the VBA project of the document that contains the RUNMACRO formula being evaluated.
The RUNMACRO function differs from the CALLTHIS function in that it does not pass a reference to the shape that owns the formula being evaluated to macroname. Like CALLTHIS, the RUNMACRO function doesn't require a reference to projname_opt to call into it.
VBA code that is invoked when the Visio instance evaluates a RUNMACRO function in a formula should not close the document containing the cell using the function because an application error results and Visio terminates.
If you need to close the document containing the cell that uses the RUNMACRO function, use one of the following techniques:
Close the document from code that is not VBA.
Close the document from a project other than the one that is closing.
Post window messages to close windows in the document rather than closing the document.
For more information about running code in Visio, see About security settings and running code in Visio in this ShapeSheet Reference.
The following example invokes a macro called MyTest in the ThisDocument class module of the VBA project containing the RUNMACRO formula.