We help IT Professionals succeed at work.

Reading command line parameter with word 2007 macro

I would like to pass a parameter from the command line to a word 2007 macro. I am able to launch the macro , but how do I pass the parameter (value of "hi" ) to my macro ?

ex: "c:\program files\microsoft office\office12\winword" /mtest "hi"

My "test" macro has a message box which I want to have read the value of "hi" and display.
Comment
Watch Question

Commented:
I think you have to pass the arguments after a /cmd

e.g.

ex: "c:\program files\microsoft office\office12\winword" /mtest /cmd "hi"

You can then read them in VBA using Command$ - as in the code shown below

Sub Command_Line_Call()

sCmdText = Trim$(Command$)

' You can give multiple parameters through command line with specific delimiters

arCmdData = Split(sCmdText, ",")
If arCmdData(0) = "PRG1" Then
Exec_PRG1 (arCmdData(1))
ElseIf arCmdData(0) = "PRG2" Then
Exec_PRG2 (arCmdData(1))
If arCmdData(0) = "PRG3" Then
Exec_PRG3 (arCmdData(1))
End If


End Sub

Open in new window