Excel macro on a DOS command line

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.
 
J

jaf

Hi Richard,
No. You can open the workbook, and if it contains a macro "Auto_Execute()"
it will run.

excel.exe path\filename.xls
 
R

Randall Arnold

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
 
D

Dave Peterson

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top