ExecExcelMacro
System function.
The ExecExcelMacro function executes an Excel macro in the specified Excel book.
Usage
Use ExecExcelMacro function to run a macro in Excel in just one line without opening Excel. The macro execution is done silently and the Excel file is saved.
Syntax
ExecExcelMacro (<workbook> ,<macro_name>,<timeout>)
or
ret=ExecExcelMacro (<workbook> ,<macro_name>,<timeout>)Parameters
<workbook>, string, name of the Excel workbook to read from. It is a string which can be a constant or a variable. Long names and UNC names are accepted, such as \\Server\c\my_directory\my_file.xls. If the path is not specified, the file is searched in the current directory.
<macro_name>, string, name of the macro to execute. At the end of the macro execution, the Excel workbook is automatically saved.
If after <timeout> seconds, the macro has not finished its execution, an error is reported (if #IgnoreErrors=1, default value) . If <timeout> is set to 0, there is no limitation for execution duration.
Return value
Ret, numeric return code. When the macro execution has ended successfully, the function returns 0. If the macro did not finish within the <timeout> the return code is set to -1 and you can use this return code for Error Handling. The return code is 2 if the specified Excel file does not exist. The return code is 107 if the specified macro does not exist in the workbook.
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)