Executing word from command prompt

M

marker

I am working of a tcl script to convert a document. This script will
be distributed to multiple people. As one of the steps in the
program,I need to open a word document and save the document as a
"text only" file. I created a macro "Convert" to open a word document
and save it as a "text only" file. I saved the macro in a file
c:\temp\Convert.bas. I understand that via the command prompt I can
call the macro. From TCL I can execute a command prompt as follow:

eval exec "winword.exe /mConvert <file to open and convert>"

Since this will be running on other systems, I need to load the macro.
Do I need to load the macro or can I reference the bas file as part of
the command to read the macro, prior to executing it? If I need to
load the macro, how to I load it via a command prompt? If I can
reference the bas file, how do I do that via the command prompt?

Thanks for your help.

Regards,
Mark
 
J

Jay Freedman

Hi, Mark,

I'm afraid you've misunderstood the relation of macros and command lines in
Word. In order to run at all, a macro must be stored in a template or a
document. In order to run Word and immediately run a macro from the command
line with the /m switch, that macro must be stored in the Normal.dot
template, which is automatically loaded when Word starts -- no other
template or document will work.

If you were going to do this only on your own PC, you might stand a chance
because you could store the macro in Normal.dot at any time before your
script needs to call it. The requirement to distribute the macro to other
users probably makes the whole scheme unworkable, unless each of them stores
the macro in their own Normal.dot before the script starts.

It is possible to programmatically import a macro from a .bas file into a
template -- but then Normal.dot needs to contain a macro to do the
importing, so you haven't gained anything.

I have only a passing acquaintance with tcl, so I don't know whether you
could use something like CreateObject to acquire a Word object and drive it
through the automation interface. You certainly could do this with a
VBScript file, so maybe you could have the tcl script run the VBScript. If
you need help with that, post back with some details like the document name
and the name you want for the text file.
 
M

marker

Hi Jay -

Thanks for your input. I read several of the previous posts with your
replies and they were very helpful. I did a bit more searching on the
web and I found more infomation and was able to use to resolve the
problem.

I created a new template (convert.dot) and saved the macro in the new
template. I then made the following command prompt call in TCL:

eval exec "winword.exe /t<path>/Convert.dot /mConvert \"<file to
convert>\""

The macro converts the file to a "text only" format and saves it in my
working directory. I have the macro quit Word so the TCL program can
continue. With the macro in the template, I am able to provide the
template as part of my software distribution.

Thanks again for your help.

Regards,
Mark
 

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