java - Jacob : calling vb function in Excel file without invoking "Open" statement -
i'm using jacob call vb function resides in macro in excel file.
here code : [i pass file , vb function name paramaters below java method]
private static void callexcelmacro(file file, string macroname) { comthread.initsta(); final activexcomponent excel = new activexcomponent("excel.application"); try { // open excel if property set true excel.setproperty("visible", new variant(false)); final dispatch workbooks = excel.getproperty("workbooks").getdispatch(); //string eventsink = null ; int id = dispatch.get(workbooks, "count").getint(); system.out.println("le nbre" + id); dispatch.call(workbooks, "add"); dispatch workbook = dispatch.call(workbooks, "open", file.getabsolutepath()).todispatch(); //new dispatchevents(sourceofevent, eventsink, progid) //new dispatchevents(workbook, w , "excel.application"); //system.out.println("le résultat"+eventsink); //d.saferelease(); variant v1 = new variant( file.getname() + macroname); // calls macro final variant result = dispatch.call(excel, "run", v1); // saves , closes //dispatch.call(workbook, "save"); com.jacob.com.variant f = new com.jacob.com.variant(true); // dispatch.call(workbook, "close", f); } catch (exception e) { e.printstacktrace(); } { excel.invoke("quit", new variant[0]); comthread.release(); } }
the code runs fine, problem don't want call instrcution
dispatch workbook = dispatch.call(workbooks, "open", file.getabsolutepath()).todispatch();
which displays me default macro executes (an interface input fields).
is there way "run" vb function without "opening" excel file ?
thanks.
there no way execute vba function in excel workbook without opening file...
of course, can prevent auto_open macro running disabling events on excel application object.
in excel vba so:
application.enableevents=false
(frequently in conjunction other settings screenupdating , displayalerts)
in java maybe use:
excel.setproperty("enableevents", new variant(false));
i hope pointers in right direction (lol, boom boom !)
philip
Comments
Post a Comment