Application.Run method (Word)

Runs a Visual Basic macro.

Syntax

expression.Run (MacroName, varg1, varg2, varg3, varg4, varg5, varg6, varg7, varg8, varg9, varg10, varg11, varg12, varg13, varg14, varg15, varg16, varg17, varg18, varg19, varg20, varg21, varg22, varg23, varg24, varg25, varg26, varg27, varg28, varg29, varg30)

expression Required. A variable that represents an Application object.

Parameters

Name Required/Optional Data type Description
MacroName Required String The name of the macro.
varg1...varg30 Optional Variant Macro parameter values. You can pass up to 30 parameter values to the specified macro.

Remarks

The MacroName parameter 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.

Although Visual Basic code can call a macro directly (without using the Run method), this method is useful when the macro name is stored in a variable. (For more information, see the example for this topic). The following three statements are functionally equivalent. The first two statements require a reference to Normal.dot, the project in which the called macro resides; the third statement, which uses the Run method, does not require a reference to the Normal.dot project.

Normal.Module2.Macro1 
Call Normal.Module2.Macro1 
Application.Run MacroName:="Normal.Module2.Macro1"

Example

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

Dim strTemplate As String 
Dim strModule As String 
Dim strMacro As String 
Dim strParameter As String 
 
strTemplate = InputBox("Enter the template name") 
strModule = InputBox("Enter the module name") 
strMacro = InputBox("Enter the macro name") 
strParameter = InputBox("Enter a parameter value") 
Application.Run MacroName:=strTemplate & "." _ 
 & strModule & "." & strMacro, _ 
 varg1:=strParameter

See also

Application Object

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.