Run Excel Macro from Command Line

A

Al Franz

Is there a way to run an Excel macro from a command line. Such as when you
open up a file to have it run the macro. Since I want to do this for files
that are newly created I can not program the file to run the macro at
startup. Is there a command line option in excel?
 
T

Tim Williams

Can you use automation to run the macro? You can create a script file
to do this and run it from the command line....

Others may have more suggestions if you can outline what it is you're
doing.

Tim.
 
M

Michael Bednarek

Is there a way to run an Excel macro from a command line. Such as when you
open up a file to have it run the macro. Since I want to do this for files
that are newly created I can not program the file to run the macro at
startup. Is there a command line option in excel?

Not to my knowledge. You have to write some VBS code for that. E.g.:

Option Explicit
Dim objXL

Set objXL = WScript.CreateObject("Excel.Application")
objXL.WorkBooks.Open "d:\dir\fubar.xls"
objXL.Visible = TRUE ' Optional
objXL.Run("yourMacro")
objXL.Quit
Set objXL = Nothing
 
G

Guest

There is no command line option in excel that will allow you to do this but
you shouldn't need to. How are you creating the new workbooks? I assume
you will do it programmatically from another workbook that you're working
from? If so then you can do whatever you need to do to this newly created
file from that workbook; even have it write the module to your new file.
Would probably need some more information on what you are trying to do so if
you can explain in more detail then I may have some example code to help you.
 

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