User`s guide
3 Programming with Excel Builder Components
3-4
Initializing Excel Builder Libraries with Excel
Before you use any MATLAB Excel Builder component, initialize the
supporting libraries with the current instance of Excel. Do this once for an
Excel session that uses MATLAB Excel Builder components. To do this
initialization, call the utility library function
MWInitApplication, a member of
the
MWUtil class. This class is part of the MWComUtil library. See the section
“Utility Library Classes” on page D-3 for a detailed discussion of the
functionality provided with this library.
One way to add this initialization code into a VBA module is to provide a
subroutine that does the initialization 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 another global variable of type
Boolean named bModuleInitialized stores the status of the initialization
process. The private subroutine
InitModule() creates an instance of the
MWComUtil class and calls the MWInitApplication 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