Excel VBA Accessing Java
This example follows on from the J-Integra® Visual BASIC to Java late binding example, and assumes you still have the JVM running, and that you got that example working.
You will put the default value associated with the Simple object (which J-Integra® automatically maps to its toString() method) into cells when the user clicks on them.
Start up Excel, and then click on Tools|Macro|Visual Basic Editor:
Double-click on Sheet 1 in the list of objects:
Add the following code which gets called when you click on the spreadsheet:
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range) Dim simple As Object Set simple = GetObject("firstjvm:Simple") Taget = simple ' Uses 'toString()" on Simple ' If the Java Simple class had a property xyz: ' Target = simple.xyz End Sub
Go back to the spreadsheet by clicking on View|Object
Click anywhere on the spreadsheet, the cell you click on should be filled with the default value associated with the Java Simple object (the result of calling toString() on it):
By running the 'java2com' tool on your existing Java classes, you should be able to create instances of them, and invoke their methods and properties from VBA. J-Integra® renders accessible all public methods and fields (even if static).