Excel macro on a DOS command line

  • Thread starter Thread starter Richard
  • Start date Start date
R

Richard

Is there a way to run an Excel macro on a DOS command
line? Something that just run a macro and then exits Excel.

I looked in Help, but don't see any command line switch
that does this.

Any suggestion is appreciated. Thanks in advance.
 
Hi Richard,
No. You can open the workbook, and if it contains a macro "Auto_Execute()"
it will run.

excel.exe path\filename.xls
 
I'm pretty sure he'll want the (now obsolete) sub Auto_Open(), or the more
current WorkBook_Open event. I don't think Auto_Execute is supported.

Randall Arnold
 
Maybe you could just use this from the DOS prompt or within a .bat file:

Start "c:\my documents\excel\book1.xls"

Name your macro (in a general module) Auto_open. Then when windows starts excel
with your workbook, your auto_open kicks in and runs your code.

Make sure you have macros enabled (so you don't have to worry about the macros
prompt).

And maybe something like:

application.quit

right at the end of your code.

When you're testing, leave this line out--or hold the shift key when opening
that workbook--so your workbook stays open.
 
Back
Top