User`s guide

Creating an Instance of a Class
3-7
Dim aClass As mycomponent.myclass
On Error Goto Handle_Error
Set aClass = New mycomponent.myclass
' (call some methods on aClass)
Exit Function
Handle_Error:
foo = Err.Description
End Function
In this example, the class instance could be dimensioned as simply myclass.
The full declaration in the form
<component-name>.<class-name> guards
against name collisions that could occur if other libraries in the current project
contain types named
myclass.
Both methods are equivalent in functionality. The first method does not
require a reference to the type library in the VBA project, while the second
results in faster code execution. The second method has the added advantage
of enabling the
Auto-List-Members and Auto-Quick-Info capabilities of the
VBA editor to work with your classes. The default function wrappers created
with each built component all use the first method for object creation.
In the previous two examples, the class instance used to make the method call
was a local variable of the procedure. This creates and destroys a new class
instance for each call. An alternative approach is to declare one single
module-scoped class instance that is reused by all function calls, as in the
initialization code of the previous example.