Call VB macro from java code

I have a VB macro. I want to pass the macro the line and file location. How can I call it in java code. Is there a library for this?

+3
source share
3 answers

You can run vbscript using "cscript.exe", which comes with windows.

Depending on your scenario, you can run this with Java in various ways:

  • use Runtime.exec to run the program. You can do this directly as part of your program.
  • use Ant, which has an exec task, or maven, which has an exec plugin. This is most useful when invoking a script as part of an assembly or some other batch process.

EDIT: If your script has a graphical interface, use "wscript.exe".

I assume you mean vbscript, but if you mean a macro such as a Word macro, then you will need to do something like this:

"C:\Program Files\Microsoft Office\Office12\Winword.exe" "C:\MyPath\MyDoc.doc" /m"Macro1" 

Alternatively, you can create a small vbscript that creates a Word application and uses the run () method to invoke the macro. You are executing this script with cscript.exe / wscript.exe.

+2
source

SourceForge has a "JACOB - Java COM Bridge". The project has a second, more obsolete home page .

And then there is a commercial (D) COM / ActiveX automation library called J-Integra , which also looks like this, thing.

Disclaimer: these are only links that I pulled from Google, I have no practical experience with these libraries.

+1
source

We use Com4J, which created a set of Java classes for us that looks identical to the ActiveX classes that can be used from Word VBA, and call them directly. This obviously only works on Windows machines, since Word does not work on Linux (unless you have a lot of time and fault).

Having got these APIs in Java, we could call any macro defined in the word.

0
source

All Articles