I added a VBA procedure (saveasdoc) to Normal.dot.
I have tested it with a .docx file:
- Saves the opened file with same name to a new .doc file.
- Exits the application MS Word.
I want to run this VBA procedure from a Java Application using the JACOB library.
Here is what I have tried :
System.out.println("Start!!");
File docfile = new File("C:/test.docx");
ActiveXComponent word = new ActiveXComponent("Word.Application");
word.setProperty("Visible", new Variant(true));
Dispatch oDocuments = word.getProperty("Documents").toDispatch();
Dispatch.call(oDocuments, "saveasdoc()", docfile.getPath()).toDispatch();
System.out.println("End!!");
The MS Word app is shown and the document is loaded, but the only claimed macro executor code is generating an exception :
SEVERE: null
com.jacob.com.ComFailException: Can't map name to dispid: saveasdoc()
at com.jacob.com.Dispatch.invokev(Native Method)
at com.jacob.com.Dispatch.invokev(Dispatch.java:625)
at com.jacob.com.Dispatch.invokev(Dispatch.java:625)
at com.jacob.com.Dispatch.callN(Dispatch.java:453)
at com.jacob.com.Dispatch.call(Dispatch.java:541)
at WordProcessing.main(WordProcessing.java:30)