Re: Trying to call a function in VBA from Java code
electrotype <[email protected]>
| Newsgroups | gmane.comp.java.ikvm.devel |
|---|---|
| Message-ID | <[email protected]> |
I found it by myself!
In Java, using the "someVbaObject" VBA object of type "cli.System.__ComObject" :
-----------------------
Method getTypeMethod = someVbaObject .getClass().getMethod("GetType");
Type type = (Type) getTypeMethod.invoke(someVbaObject);
Object result = type.InvokeMember("inform", BindingFlags.wrap(BindingFlags.InvokeMethod), null,
someVbaObject, null);
-----------------------
On 3/16/2014 9:15 AM, electrotype wrote:
> Hello,
>
> Thanks to IKVM, I have been able to create a .dll that is written in Java and can be used from
> within VBA in Excel.
>
> The only thing I didn't find is a way for the Java code to inform the VBA code when something
> occures. For example, I'd like a Java method which would look like this :
>
> Java
> -----------------------
> private ICallback callback;
> public void setCallback(ICallback callback) {
> this.callback = callback;
> }
>
> // And later....
> callback.inform();
>
> -----------------------
>
> In other words, I would like the dll to be able to call a function/method of the VBA code when it
> needs to!
>
> Any idea on how to achieve this?
>
> What I tried :
>
> 1. Using "AddressOf"
>
> VBA
> -----------------------
> Public Sub CallbackFunction()
> MsgBox "Hello"
> End Sub
>
> Dim manager As Object
> Set manager = CreateObject("myDll")
>
> manager.setCallbackFunctionPointer AddressOf CallbackFunction
> -----------------------
> In java I then receive a "cli.System.Int32" object. But how can I use this to call the VBA function?
>
> 2. Passing an object
>
> VBA
> -----------------------
> manager.setCallback someVbaObject
> -----------------------
> In java I then receive a "cli.System.__ComObject" object. But I don't know what to do with it...
> How can I call a function on it?
>
> Thanks for any help!!
>
>
------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/13534_NeoTech