User`s guide

2 Programming with MATLAB Builder for Excel
Creating an Instance of a Class
Before calling a class method (compiled MATLAB function), you must
create an instance of the class that contains the method. VBA provides two
techniques for doing this:
CreateObject function
New operator
CreateObject Function
This method uses the Visual Basic application program interface (API)
CreateObject function to create an instance of the class. To use this method,
Dim a variable of type Object to hold a reference to the class instance and
call
CreateObject using the class program matic identifier (ProgID)asan
argument, as shown in the next example:
Function foo(x1 As Variant, x2 As Variant) As Variant
Dim aClass As Object
On Error Goto Handle_Error
aClass = CreateObject("mycomponent.myclass.1_0")
' (call some methods on aClass)
Exit Function
Handle_Error:
foo = Err.Description
End Function
New Operator
This method uses the Visual Basic New operator on a variable explicitly
dimensioned as the class to be created. Before using this method, you must
reference the type library containing the class in the current VBA project.
Do this by selecting the Tools menu from the Visual Basic Editor, and then
selecting References to display the Available References list. From this
list, select the necessary type library.
The following ex ample illustrates using the
New operator to create a class
instance. It assumes that you have selected mycomponent 1.0 Type
Library from the Available R eferences list before calling this function.
2-6