Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I basically see three options for calling VBA code in Excel from a Java application:</p> <ol> <li><p><strong>Java COM Bridge</strong>: 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 <a href="http://sourceforge.net/projects/jacob-project/" rel="noreferrer">Jacob</a> and <a href="http://sourceforge.net/projects/jcom/" rel="noreferrer">JCom</a>, but there might more such tools available.</p></li> <li><p><strong>Java / VBScript / COM Automation</strong>: 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 <code>Runtime.getRuntime().exec("cmd /c start script.vbs");</code></p></li> <li><p><strong>JNI</strong>: 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.</p></li> </ol> <p>Whatever your solution will be, you basically want to execute the following commands on Excel automation interface (sample in VBScript):</p> <pre><code>Dim xl Set xl = CreateObject("Excel.Application") xl.Workbooks.Open ("workbook.xlsx") xl.Application.Run "MyMacro" xl.Application.Quit Set xl = Nothing </code></pre> <p>You cannot compile VBA code into a DLL. There exists no tool for that (in contrast to the full Visual Basic).</p> <p>I hope this answer is helpful even though I didn't understand what you mean by: <em>"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."</em></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload