Run Method

Applies To

Application object.

Description

Runs a Visual Basic macro.

Syntax

expression.Run(MacroName)

expression   An expression that returns an Application object.

MacroName   Required String. The name of the macro. Can be any combination of template, module, and macro name. For example, the following statements are all valid.

Application.Run "Normal.Module1.MAIN"
Application.Run "MyProject.MyModule.MyProcedure"
Application.Run "'My Document.doc'!ThisModule.ThisProcedure"
If you specify the document name, your code can only run macros in documents related to the current context — not just any macro in any document.

Remarks

Although Visual Basic code can call a macro directly (without this method being used), this method is useful when the macro name is stored in a variable (for more information, see the example for this topic). The following two statements are functionally equivalent:

Normal.Module2.Macro1
Application.Run MacroName:="Normal.Module2.Macro1"
You cannot pass parameters to a macro by using the Run method.

See Also

RunAutoMacro method.

Example

This example prompts the user to enter a template name, module name, and macro name, and then it runs that macro.

t = InputBox("Enter the template name")
md = InputBox("Enter the module name")
m = InputBox("Enter the macro name")
Application.Run MacroName:=t & "." & md & "." & m