java - How to execute ms word VBA with JACOB -
i added vba procedure (saveasdoc) normal.dot.
i have tested .docx file:
- saves opened file same name new .doc file.
- exits application ms word.
i want run vba procedure java application using jacob library.
here 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 shown , document loaded, claimed macro executor code generating exception :
severe: null com.jacob.com.comfailexception: can't map name dispid: saveasdoc() @ com.jacob.com.dispatch.invokev(native method) @ com.jacob.com.dispatch.invokev(dispatch.java:625) @ com.jacob.com.dispatch.invokev(dispatch.java:625) @ com.jacob.com.dispatch.calln(dispatch.java:453) @ com.jacob.com.dispatch.call(dispatch.java:541) @ wordprocessing.main(wordprocessing.java:30)
you want application.run (http://msdn.microsoft.com/en-us/library/aa220716(v=office.11).aspx)
not tested general direction should pursuing:
system.out.println("start!!"); file docfile = new file("c:/test.docx"); activexcomponent application = new activexcomponent("word.application"); dispatch.call(application, "run", new variant("saveasdoc"), new variant(docfile.getpath())); system.out.println("end!!");
Comments
Post a Comment