How to open word document with /m “Macro argument” from java/or command-line without to specifi winword.exe path

删除回忆录丶 提交于 2019-12-10 10:19:47

问题


I want to do the next thing:

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

But, without to specify the winword.exe path but open the document with the macro...

I read that there exist Auto Open macro, is it possible to specify input arguments for Auto Open macro?

SOLVED:

String[] cmd  = {"cmd","/c","start","WINWORD.exe","/mOpenPage","c:\\Navodilo_za_uporabo_spletnega_servisa_wsEdp.doc"};
Process proc = Runtime.getRuntime().exec(cmd);

It runs default winword.exe and open word document with specified Macro


回答1:


I see two options for you:

  1. Read the path to winword.exe from the Registry. It is stored under

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\12.0\Word\InstallRoot
    

    where 12.0 needs to be the correct Office version (Office 2007 = 12, Office 2003 = 11 etc).

  2. Instead of using the /m switch you could also use an auto macro. How this is done is described here:

    http://support.microsoft.com/kb/211659



来源:https://stackoverflow.com/questions/2554444/how-to-open-word-document-with-m-macro-argument-from-java-or-command-line-wit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!