0

I am looking to be able to execute code from a Java project inside an Excel VBA sheet. Elsewhere on SO, I have discovered IKVM, which is a .NET implementation of Java which allows converting a .jar into a .dll. I was hoping this would let me access the classes/methods from the .jar inside the VBA editor, but I am having trouble doing so.

I have tried using the declare statement in VBA (in many different permutations, attempting to make it work) but the most common error refers to entry points in the .DLL.

I have also tried registering the .DLL as a reference in Excel, but it gives a boilerplate error and does not register it.

As a reference, I've been testing it using the following class before bothering to test it with the whole project:

public class IKVMTest {
    public static void print(String s) {
        System.out.println(s);
    }
}

This class is compiled by Eclipse and exported into IKVMTest.jar. At this point, I use ikvmc -target:library IKVMTest.jar to receive IKVMTest.dll. For simplicity's sake, this .dll and the Excel sheet I am testing in are dumped in the IKVM bin folder (since there are some dependencies on the IKVM .dll files).

If I could get it working for this sample test, I could get it working for the project overall.

Chris J
  • 43
  • 4
  • I posted an example here: http://stackoverflow.com/questions/14967080/how-do-i-make-a-dll-created-with-ikvm-com-visible/14975883#14975883 – Jeroen Frijters Feb 20 '13 at 09:06

1 Answers1

2

Have you tried making your .NET assembly COM visible so you can use VBA to instantiate it?

using [ComVisible(true)] on the class and methods generated by the IKVM code might make it visible as a COM object to your VBA app.

Have a look here for reference: http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.comvisibleattribute.aspx#Y1600

Also, have a look here: How to call a .net assembly in VBA using COM Interop http://blogs.msdn.com/b/smondal/archive/2009/08/31/how-to-call-a-net-assembly-in-vba-using-com-interop.aspx

Carlos Quintanilla
  • 12,937
  • 3
  • 22
  • 25
  • Question, while I look through the two links you gave: using ComVisible(true) is something that I would apply to a VBA class, right? Does that imply I need to make a wrapper class in VBA for all the Java classes that I would like to refer to? – Chris J Jul 29 '11 at 16:07
  • 1
    No, the comvisible needs to be applied to .NET assemblies. Using the IKVM that generates a dll from a jar you will then need to update those dlls to include the comvisible or use the utility exe so you can make it visible to your VBA project. – Carlos Quintanilla Jul 29 '11 at 19:04