ExecuteExcel4Macro Method

Applies To

Application Object.

Description

Runs a Microsoft Excel 4.0 macro function and returns the results of the function. Returned type depends on the function. Read-write.

Syntax

object.ExecuteExcel4Macro(string)

object

Optional. The Application object.

string

Required. A Microsoft Excel 4.0 macro language function without the equal sign. All references must be given as R1C1 strings. If string contains embedded double quotation marks, then you must double them. For example, to run the macro function =MID("sometext",1,4), string would have to be "MID(""sometext"",1,4)".

Remarks

The Microsoft Excel 4.0 macro is not evaluated in the context of the current workbook or sheet. This means that any references should be external and should specify an explicit workbook name. For example, to run a Microsoft Excel 4.0 macro "My_Macro" in Book1 you must use "Book1!My_Macro()". If you do not specify the workbook name, this method fails.

See Also

Run Method.

Example

This example runs the GET.CELL(42) macro function on cell C3 on Sheet1 and displays the result in a message box. The GET.CELL(42) macro function returns the horizontal distance from the left edge of the active window to the left edge of the active cell. This macro function has no direct Visual Basic equivalent.


Worksheets("Sheet1").Activate
Range("C3").Select
MsgBox ExecuteExcel4Macro("GET.CELL(42)")