Home > Language Reference > Excel Functions > ExecExcelMacro

ExecExcelMacro

The ExecExcelMacro function executes an Excel macro in the specified Excel worksheet.

Usage

Used to run an Excel macro without opening the worksheet. The macro execution is done silently and the Excel file is saved.

Syntax

ret = ExecExcelMacro(<Excel_filename>,<macro_name>,<timeout>)

Parameters

<Excel_filename>, string, Excel filename. If the path is not specified, the file is searched in the current working folder.

<macro_name>, string, name of the macro to execute. At the end of the macro execution, the Excel workbook is automatically saved.

<timeout>, integer. If after <timeout> seconds, the macro has not finished its execution, an error is reported (if #IgnoreErrors=1, default value) and script execution stops. If <timeout> is set to 0, there is no limitation for execution duration.

Return value

ret, optional numeric return value. If the function succeeds, the return value is 0. If the macro did not finish within the <timeout> the return code is set to -1 (see File Functions Error Codes).

See also

CloseExcelCom
CreateExcelFile
ReadExcel
WriteExcel

Examples

ExecExcelMacro("c:\my documents\my_excel_file.xls", "my_macro",0)

ExecExcelMacro("c:\my documents\my_excel_file.xls", "PERSONAL.XLS!my_macro",30)

excelfile$="c:\my documents\my_excel_file.xls"
macro$="my_macro"
ExecExcelMacro(excelfile$,macro$,10)