ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Excel macro on a DOS command line (https://www.excelbanter.com/excel-programming/271845-excel-macro-dos-command-line.html)

Richard[_13_]

Excel macro on a DOS command line
 
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.


jaf

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

excel.exe path\filename.xls


--

John

johnf202 at hotmail dot com


"Richard" wrote in message
...
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.




Randall Arnold[_2_]

Excel macro on a DOS command line
 
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

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

excel.exe path\filename.xls


--

John

johnf202 at hotmail dot com


"Richard" wrote in message
...
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.






Dave Peterson[_3_]

Excel macro on a DOS command line
 
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.



Richard wrote:

To run VBScript, I would need to subscribe to MSDN, yes?

-----Original Message-----
Another alternative would be to drive Excel from

VBScript. You could create
some VBScript which does whatever you want (open files,

manipulate them,
save etc) which can be executed from a command prompt.

This is more of a suggestion for what may be another way

of doing what
you're trying to acheive. As the other poster's said

there are only a
couple of events which are fired when a workbook opens

and unless they are
in place nothing will happen when the workbook loads.

If you're interested in a short primer on VBScript look at

http://www.billlunney.com/Excel/FAQ/DisplayFAQ.ascx?

ExcelFAQID=129



--

Regards,


Bill Lunney
www.billlunney.com

"Richard" wrote in message
...
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.



.


--

Dave Peterson



All times are GMT +1. The time now is 06:08 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com