
Signature
Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
> Hi Rhino,
>
[quoted text clipped - 7 lines]
> and have the macro "test00001" e.g.
> read a txt-file with all the information you need.
Excellent, that works!
Now, do you have any idea how to pass a parameter to the macro on the
command line? Something like:
c:\prg\mso2003\office11\winword.exe /mtest00001 Arial
if you wanted to compose the document using the Arial font family?
(I'm not actually trying to direct the macro which font family to use; I
really just need to know the principle of how to pass a parameter to the
macro and how to get the macro to use it.)
Rhino
Helmut Weber - 27 Jan 2006 23:39 GMT
Hi Rhino,
>Now, do you have any idea
>how to pass a parameter to the macro on the command line?
no.
Somebody else may know better.
Anyway, the number of the command line arguments would be limited.
In theory,
only the operating system and the hardware set the boarders.
With reading from a txt-file or any other file,
the possibilities would be _almost_ unlimited.

Signature
Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
Jay Freedman - 28 Jan 2006 00:23 GMT
>> Hi Rhino,
>>
[quoted text clipped - 22 lines]
>
>Rhino
Hi Rhino,
No, there's no facility for passing parameters on the command line.
(The full story on command-line switches is at
http://support.microsoft.com/?kbid=210565.) That's why Helmut told you
to have the macro read its information from a text file or other kind
of file (whose path and name must be constant because you can't pass
that on the command line either). An alternative is to have the
information stored in a known place in the registry.
--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
Steve Yandl - 28 Jan 2006 00:50 GMT
Rhino,
If I were you, I'd use vbScript and take advantage of the fact that the
Windows Script Host has an arguments collection. In the example below, I
have a Word document named TestDoc.doc that resides in the MyDocuments
folder and contains a macro named MyMacro that takes two arguments as text
strings. If I make a text file with the code below and name it with a vbs
extension, I can launch with my arguments as follows:
C:\Test\LaunchWdMacro.vbs StringA StringB
Word runs but isn't visible. The macro runs and takes the two arguments.
Code below.
' Get arguments into variables
If WScript.Arguments.Count < 2 Then
MsgBox "Not enough arguments"
WScript.Quit
Else
strArg1 = WScript.Arguments.Item(0)
strArg2 = WScript.Arguments.Item(1)
End If
' Find path for MyDocuments folder
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(&H5&)
strMyDocPath = objFolder.Self.Path
' Start Word Application, open TestDoc.doc in MyDocuments
Set oWd = CreateObject("Word.Application")
oWd.Visible = False
Set oDoc = oWd.Documents.Open(strMyDocPath & "\TestDoc.doc")
' Run macro named MyMacro with two string arguments
oWd.Run "MyMacro",strArg1,strArg2
' Save changes to doc on closing and quit Word
oDoc.Save
oDoc.Close
oWd.Quit
Set oWd = Nothing
Set objShell = Nothing
Steve
>> Hi Rhino,
>>
[quoted text clipped - 22 lines]
>
> Rhino
Rhino - 28 Jan 2006 22:11 GMT
Wow, I really like the approach you're suggesting!
I've tried your example and it worked fine so I think I will use it for my
project. However, I will keep the other suggestions in mind as a backup, in
case I start running into unexpected problems with your approach.
Thanks very much for the suggestion!
--
Rhino
> Rhino,
>
[quoted text clipped - 67 lines]
>>
>> Rhino
Steve Yandl - 28 Jan 2006 22:40 GMT
You're welcome.
I'd probably create an instance of the file system object,
Set objFSO = CreateObject("Scripting.FileSystemObject")
and use it to check for files and folders or to delete if that is what you
want. It sounded like you already have that written into your macro and I
didn't want to confuse matters by duplication of effort but you might find
it to be a workable option.
I still use batch files from time to time but vbScript gives you so much
more in the area of controlling objects (the different Office applications
for example) that I've pretty much converted to vbs for this type project.
Steve Yandl
> Wow, I really like the approach you're suggesting!
>
[quoted text clipped - 78 lines]
>>>
>>> Rhino