commandline argument in excel 2003

G

Guest

I want to pass command line argument to to the VBA code in EXCEL 2003. I
cannot use Command() or COmmand$().

Kindly suggest how should i go about it?

Thanks
 
G

Guest

From "Microsoft Visual Basic Help":

"The Visual Basic Command function is not available in Microsoft Office
applications."

So forget about the command() function.

You might have to consider using Office Automation.
If you are familar with visual basic you can do automation with Windows
Scripting Host:
- create a Windows Scripting Host file that creates an excel application
object.
- call the run method on the object passing the macro name that you want to
execute + command line arguments

Something like this:

' ---------------------------
' automate.vbs
' ---------------------------
Dim app, wb, args

Set args = WScript.Arguments
Set app = CreateObject("Excel.Application")
Set wb = app.Workbooks.Open("c:\myfile.xls")

app.Run "Module1.MyMacro", args(0)

wb.Close
app.Quit
Set wb = Nothing
Set excel = Nothing
' ---------------------------

Try calling automate.vbs from command line prompt, e.g.
c:\> automate.vbs param1 param2


Hope this helps -- arunkhemlai
(e-mail address removed)
 

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