views:

255

answers:

3

Hello everybody!

when I write in commandline in windows:

C:\Program Files (x86)\Microsoft Office\Office12>winword.exe /mOpenPage c:\Navod
ilo.doc

It starts the word document with the macro /mOpenPage. I want to do the same thing from Java but its not going.

String[] cmd  = {"cmd","/c","c:\\Program Files (x86)\\Microsoft Office\\Office12\\WINWORD.exe","/mOpenPage","c:\\Navodilo.doc"};
Process proc = Runtime.getRuntime().exec(cmd);

and how to open the document without to specify the path to winword.exe? but also to use /mOpenPage Macro

help?

A: 

Runtime.getRuntime.exec() does not open up a cmd window you have to invoke it with "cmd" as its argument and then use the inputstream to send you winword.execommand

http://forums.sun.com/thread.jspa?threadID=138974&tstart=140442

Yaneeve
Edited, I tried with just "cmd" but again it doesnt open the document
Milan
take a look at the link I added, something like what tushar_zaware says
Yaneeve
+1  A: 

Try this:

String cmd = "c:\\Program Files (x86)\\Microsoft Office\\Office12\\WINWORD.exe /mOpenPage c:\\Navodilo.doc";
Process proc = Runtime.getRuntime().exec(cmd);
Thomas
Thanks, yours is also working.
Milan
and how to opent the document without to specify the path to winword.exe? but also to use /mOpenPage Macro
Milan
Sorry, but that is too much of a change to your original question ;-) I'm not on Windows so I can't help you with that.
Thomas
A: 

You should try using Desktop.open(File file) which will open the default application for your Word document. This is a better approach as you don't have to worry about where Office is installed.

Steve Kuo
And how would he pass the `/mOpenPage` flag?
Thomas