Calling Crystal Ball From an External Visual Basic (VB) Program

Using Crystal Ball from Visual Basic 4.0 or higher is somewhat more complicated than using it from Visual Basic for Applications.

To access Crystal Ball calls, you must first get a reference to the Microsoft Excel application object. To do this, run the following procedure before running Crystal Ball subroutines and functions:

Private Sub LoadCB()
   On Error Resume Next
   Set XL = CreateObject("Excel.Application").Parent
   XL.Visible = True
   Set CB = XL.Workbooks("CBDevKit.xla").Modules("CB")
   If Not IsObject(CB) Then
      Set CB = XL.Workbooks.Open(filename:= _
         "C:\Program Files\Oracle\Crystal Ball\CBDevKit.xla")
End If
End Sub

If you have stored the file CBDevKit.xla in some other directory than C:\Program Files\Oracle\..., then substitute the appropriate path name.

This procedure gets a reference to the Microsoft Excel application object and puts it into variable XL. Then this variable is used to determine if Crystal Ball is already loaded.

If the Crystal Ball Developer Kit is not loaded, the procedure loads it.

You cannot use Crystal Ball as an OLE automation object. You should call its subroutines and functions through a call to Microsoft Excel’s Run macro. The first parameter is the name of a Crystal Ball subroutine or function. Other parameters are passed to the specified Crystal Ball call.

For example the following call to CB.Simulation from a VBA module

It is easy to translate code written in Visual Basic for Applications into Visual Basic code.

CB.Simulation 1000, True

can be replaced by the VB equivalent

XL.Run "CB.Simulation", 1000, True

Note:

Crystal Ball subroutine and function names are case sensitive when called from outside Microsoft Excel. Be sure to capitalize the CB module name that prefixes the call names. In all other respects, calling Crystal Ball from VB 4.0 is no different from calling it from VBA.