How to run VBA macro from Amibroker Batch

Hey everyone,

I am looking to find a way (preferably through Amibroker batch) to execute an excel macro, But I have not been able to find much on the subject.

So far, I have been able to execute the excel file itself via batch ‘execute and wait’:
cmd.exe /c start excel "C:\Program Files\AmiBroker\Formulas\Excel\example.xlsm"

Any help to take the next step to run the VBA macro would be greatly appreciated!

1 Like

It is not VBA Support forum.
You should look at MS page.

/// 1. Set path to Excel file and name and arguments of macro below
/// 2. Open your Excel file
/// 3. Run Explorer (or click ParamTrigger of chart pane).
/// @link
Version(6.40); // because of GetObject function
xls_file = "Book1.xlsm";
path = "C:\\"+ xls_file;
macro = "Macro1";
explore = Status("action") == actionExplore;
trigger = explore OR ParamTrigger("Execute Macro", "CLICK HERE");
if ( trigger ) {	
	obj = GetObject(path, "");
	excel = obj.Application;
	if ( excel ) {
		excel.Run(xls_file + "!" + macro);
	} else 
		Error( "No Excel object" );	



As usual, thankyou very much fxshrat for the swift and clear solution.

Further clarification for future readers is that you will receive a error if the excel file name has spaces, so name the file "Book1" not "Book 1" :nerd_face:

1 Like

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.