Run Method

Applies To

Application Object, Range Object.

Description

Syntax 1: Runs a macro or calls a function. This can be used to run a macro written in any language (Visual Basic, the Microsoft Excel 4.0 macro language, or a function in a DLL or XLL).

Syntax 2: Runs the Microsoft Excel 4.0 macro at this location. The range must be on a macro sheet.

Syntax 1

object.Run(macro, arg1, arg2, ...)

Syntax 2

object.Run(arg1, arg2, ...)

object

Optional for Application, required for Range. The application that contains the macro, or a range on a macro sheet that contains an Microsoft Excel 4.0 macro.

macro

Required for Syntax 1 (not used with Syntax 2). The macro to run. This can be a string with the macro name, or a Range indicating where the function is, or a register ID for a registered DLL (XLL) function. If a string is used, the string will be evaluated in the context of the active sheet.

arg1, arg2, ...

Optional. The arguments that should be passed to the function.

Remarks

The Run method returns whatever the called macro returns. Objects passed as arguments to the macro are converted to values (by applying the Value property to the object). This means you cannot pass objects to macros using the Run method.

Example

This example shows how to call the function macro My_Func_Sum, which is defined on the macro sheet MYCUSTOM.XLM (the macro sheet must be open). The function takes two numeric arguments-1 and 5, in this example.


mySum = Application.Run("MYCUSTOM.XLM!My_Func_Sum", 1, 5)
MsgBox "Macro result: " & mySum