jump to navigation

How to execute Visual Basic from JAVA ? – part 2 – autostart your VB… July 11, 2009

Posted by pierrekoerber in Uncategorized.
trackback

In our last article we have seen how to start word from JAVA. Now we will start word with a document in parameter and then we will put an autoopen marcro in our document.

JAVA – Code

String sCmd ;

sCmd = “C:\\Program Files\\Microsoft Office\\OFFICE11\\winword.exe ” + “\”c:\\Mes documents\\Doc3.doc\”" ;

try {
Runtime.getRuntime().exec(sCmd);
} catch (IOException e) {
e.printStackTrace();
}

This will start word with a special document.

The next step is how to autostart the VB code.

You can put in your document macro the autoopen, which will automatically starts when the document is launch

VB – Code in the document

Sub autoopen()

Load UserForm1
UserForm1.Show

End Sub

Ok, this is a simple way to starts VB from JAVA. Of course you can’t synchronise your programs and also you can’t pass parameters. This is not a perfect integration but it can helps you to reuse easily something which exists already on your system.
Of course it breaks the main advantage of JAVA to be multi-system, but the world isn’t perfect… for now.

Greetings.

Comments»

1. Mathieu SCHROETER - July 13, 2009

Hi Pierre,

you can write a wrapper in C/C++ to bridge Java with a VB DLL.

Java C/C++ bridge your wrapper in C/C++ (DLL) C/C++ bridge VB

IMHO, Java and VB can access to a C/C++ apps without additions.

2. Mathieu SCHROETER - July 13, 2009

My previous comment was altered by wordpress…

second line is something like that :

Java [link to] C/C++ bridge [link to] your wrapper in C/C++ (DLL) [link to] C/C++ bridge [link to] VB