User`s guide

2 Programming with MATLAB Builder for Excel
Initializing M ATLAB Builder for E xcel Libraries with Excel
Before you use any MATLAB Builder for Excel component, initialize the
supporting libraries with the current instance of Excel. Do this once for an
Excel session that uses Excel Builder components.
To do this initialization, call the utility library function
MWInitApplication,
which is a member of the
MWUtil class. This class is part of the MWComUtil
library. See “Utility Library Classes” on page C-3 for a detailed discussion of
the functionality p rovided with this library.
OnewaytoaddthisinitializationcodeintoaVBAmoduleistoprovide
a subroutine that does the initiali zation once, and simply exits for all
subsequent calls. The following Visual Basic code sample initializes the
libraries with the current instance of Excel. A global variable of type
Object
named MCLUtil holds an instance of the MWUtil class, and a nother global
variable of type
Boolean named bModuleInitialized stores the status of
the initialization process. The private subroutine
InitModule() creates
an instance of the
MWComUtil classandcallstheMWInitApplication
method with an argument of Application. Once this function succeeds, all
subsequent calls exit without reinitializing.
Dim MCLUtil As Object
Dim bModuleInitialized As Boolean
Private Sub InitModule()
If Not bModuleInitialized Then
On Error GoTo Handle_Error
If MCLUtil Is Nothing Then
Set MCLUtil = CreateObject("MWComUtil.MWUtil")
End If
Call MCLUtil.MWInitApplication(Application)
bModuleInitialized = True
Exit Sub
Handle_Error:
bModuleInitialized = False
End If
End Sub
2-4