score:9

Accepted answer

i basically see three options for calling vba code in excel from a java application:

  1. java com bridge: there are several tools available that allow you to call com or com automation components from java. excel is such a component. i know of jacob and jcom, but there might more such tools available.

  2. java / vbscript / com automation: since you obviously don't need to pass data to the vba code, the simplest solution is probably to write a vbscript that starts excel, opens the document, calls the macro and closes excel. this script is started from java with runtime.getruntime().exec("cmd /c start script.vbs");

  3. jni: you could write a specific dll for your applications. it implements the jni interface so it can be called from java. and its implementation uses com calls to work with excel. such a dll is best written with visualstudio and it's support for c++ to call com objects.

whatever your solution will be, you basically want to execute the following commands on excel automation interface (sample in vbscript):

dim xl
set xl = createobject("excel.application")
xl.workbooks.open ("workbook.xlsx")
xl.application.run "mymacro"
xl.application.quit
set xl = nothing 

you cannot compile vba code into a dll. there exists no tool for that (in contrast to the full visual basic).

i hope this answer is helpful even though i didn't understand what you mean by: "we want to assume that the user of the java application does not necessarily have immediate access to excel, but is operating on a windows machine."


Related Query

More Query from same tag