ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   passing parameters from command line (https://www.excelbanter.com/excel-programming/290886-passing-parameters-command-line.html)

Albrecht Hesmert

passing parameters from command line
 
Hi,

I want to pass parameters to an excel macro when calling it from command
line.

e.g. something like:

excel myexcel.xls filename.txt

The excel macro should process the file filename.txt
Is this possible? What do I have to do in the macro to access the
parameter?

Thanks & regards,
Albrecht


arno

passing parameters from command line
 
Hi Albrecht,

I want to pass parameters to an excel macro when calling it from command
line.


Never heard of this.

You could use an auto_open makro or workbook_open-event in the xls-file.
However, this will also run everytime *you* open the file.

My second solution (that I use under other circumstances) is to have a
second excel file that has an workbook_open event that will open your file
and call a makro there that will do what you want. You could start the
second file in your batchfile, command prompt or whatever. (Sounds
complicated but with this method I can run 30 reports automatically every
day. All these reports have the same macro.)

Best regards

arno




Albrecht Hesmert

passing parameters from command line
 
Hi Arno,

thanks for the reply.
Still: When I use Auto_Open, how do I get the parameter (e.g. the filename,
that changes every day)?

Regards,
Albrecht

arno schrieb:

Hi Albrecht,

I want to pass parameters to an excel macro when calling it from command
line.


Never heard of this.

You could use an auto_open makro or workbook_open-event in the xls-file.
However, this will also run everytime *you* open the file.

My second solution (that I use under other circumstances) is to have a
second excel file that has an workbook_open event that will open your file
and call a makro there that will do what you want. You could start the
second file in your batchfile, command prompt or whatever. (Sounds
complicated but with this method I can run 30 reports automatically every
day. All these reports have the same macro.)

Best regards

arno



Albrecht Hesmert

passing parameters from command line
 
Hi Arno,

thanks for the reply.
Still: When I use Auto_Open, how do I get the parameter (e.g. the filename,
that changes every day)?

Regards,
Albrecht

arno schrieb:

Hi Albrecht,

I want to pass parameters to an excel macro when calling it from command
line.


Never heard of this.

You could use an auto_open makro or workbook_open-event in the xls-file.
However, this will also run everytime *you* open the file.

My second solution (that I use under other circumstances) is to have a
second excel file that has an workbook_open event that will open your file
and call a makro there that will do what you want. You could start the
second file in your batchfile, command prompt or whatever. (Sounds
complicated but with this method I can run 30 reports automatically every
day. All these reports have the same macro.)

Best regards

arno



arno

passing parameters from command line
 
Hi Albrecht,

Still: When I use Auto_Open, how do I get the parameter (e.g. the

filename,
that changes every day)?


That's a different story. There _must_ be a rule to find out the filename.
If you create the filename, then I would use the same name every day. If
this is not possible the you have to know what the name is, eg. it has
always todays date. Then you can have a macro like this:

myFile = "testFile"
myExtension = ".txt"
myDate = format(today(), "DDMMYYYY")

myFiletoOpen = myFile & myDate & myExtension

then you can do with myFiletoOpen whatever you like (it will be
"testFile11022004.txt" for today).

regards

arno



arno

passing parameters from command line
 
oops,

sorry, it should be

myDate = Format(Date, "DDMMYYYY")


arno




All times are GMT +1. The time now is 12:34 PM.

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