Aleksey Nagoga.


Hi All,

Back in the Office 97 days I tried passing command line arguments to VBA code within a doc file and it didn't work. In the end I found a workaround that was a bit of a hassle to implement but did what I needed.

Today, I found myself in a need of accomplishing a similar task in the Office 2003, plus the solution must also work in the Office 2007.

I was wondering if MSFT finally added the command line arguments support in VBA or I need to go back to the old tricks.

Basically I'm looking to do something like:

winword.exe "MyDocument.doc" "/cmd MyVBAArgument1=A MyVBAArgument2=B"

Thanks,

Aleksey




Re: Is Office2003 still does not support passing command line arguments to VBA?

jhoski


I need to do the same thing and have been searching the VB 2003 reference with no luck. Can you expand on your work arounds Thanks, Jay





Re: Is Office2003 still does not support passing command line arguments to VBA?

Aleksey Nagoga.

Sure. I wrote an intermediate application, I think I named it VBACMD, that was setting a special environment variable that the VBA code was reading on the other side. The way it worked was:

First you call the vbacmd app and pass the parameters in the following format:

vbacmd.exe <officeApp.exe_and_whatever_command_line_arguments_passed> <VBA_command_line_arguments>

(officeApp.exe represents any of the office executables like winword.exe, excel.exe, etc)

then vbacmd.exe would strip off the last argument of its command line (i.e <VBA_command_line_arguments>) and assign it the environment variable VBACMDArg

then vbacmd.exe would call <officeApp.exe_and_whatever_command_line_arguments_passed>

and then the VBA code would be responsible for reading and clearing the VBACMDArg variable after itself.

That's all

Hope it helps.

Aleksey