morinia
asked on
Executing an Excel Macro outside of Excel in a Bat or VB Script
Is there a way to execute a macro in Excel from at Bat File or VB Script file?
You can use VBScript to automate Excel and run the macro that way (though there can be issues if you want to do this with task scheduler), or you can put the macro into the Workbook_Open event and use a batch file to shell excel and load that workbook and the code will run automatically. Any preference?
ASKER
Rorya,
Can you give me an example of both ways? I would like to do this with task manager at some point, but it is not mandatory at this time.
morinia
Can you give me an example of both ways? I would like to do this with task manager at some point, but it is not mandatory at this time.
morinia
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Your batch file could be as simple as:
START "C:\program files\microsoft office\office10\excel.exe" "c:\book1.xls"
changing paths as required.
Regards,
Rory
START "C:\program files\microsoft office\office10\excel.exe"
changing paths as required.
Regards,
Rory
Oh yeah, can't you also use a /m switch to run a specific macro?
START "C:\program files\microsoft office\office10\excel.exe" "c:\book1.xls" /m "MacroName"
I think I've read that somewhere?
Or would you have to use an Auto_Exec macro within that workbook?
Regards,
Rob.
START "C:\program files\microsoft office\office10\excel.exe"
I think I've read that somewhere?
Or would you have to use an Auto_Exec macro within that workbook?
Regards,
Rob.
/m is supposed to create a new workbook with a single macro sheet. I would use Workbook_Open rather than AutoExec but it's not a big deal in this case.