hdman31
07-24-2010, 02:29 PM
Hi,
I'm fairly new to using VB and needed some help on the following problem:
I was working with a Matlab builder example in Matlab to compile and build m-files into COM objects for Excel. Essentially, the building process creates a .bas file which can be imported into Visual Basic Editor in MS Excel. In the VB code, the Matlab functions essentially end up being wrapped up inside COM objects and you can invoke these functions in the excel spreadsheet.
The example works successfully for output to a single cell. For outputing to multiple cells simultaneously, the code changes a little as a macros are instead used. This gives me error 429 ActiveX problem. Any insight or help would be appreciated. I've attached part of the code below which comes from the Matlab builder magic square example. The line with the error is
CreateObject("xlmagic.xlmagicclass.1_0")
Thanks.
Dim MCLUtil As Object
Dim bModuleInitialized As Boolean
Dim xlmagicclass As Object
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
Sub mymagic()
Dim R1 As Range 'Input value
Dim R2 As Range 'Output range
On Error GoTo Handle_Error
Call InitModule
Set R1 = Range("A2") 'Specify where the input value is.
Set R2 = Range("B2:E5") 'Specify that range for the output to use.
If xlmagicclass Is Nothing Then
Set xlmagicclass = CreateObject("xlmagic.xlmagicclass.1_0")
End If
Call xlmagicclass.mymagic(1, R2, R1)
Exit Sub
Handle_Error:
MsgBox ("Error: " & Format(Err.Number) & " Source: " & Err.Source & " Message: " & Err.Description)
End Sub
I'm fairly new to using VB and needed some help on the following problem:
I was working with a Matlab builder example in Matlab to compile and build m-files into COM objects for Excel. Essentially, the building process creates a .bas file which can be imported into Visual Basic Editor in MS Excel. In the VB code, the Matlab functions essentially end up being wrapped up inside COM objects and you can invoke these functions in the excel spreadsheet.
The example works successfully for output to a single cell. For outputing to multiple cells simultaneously, the code changes a little as a macros are instead used. This gives me error 429 ActiveX problem. Any insight or help would be appreciated. I've attached part of the code below which comes from the Matlab builder magic square example. The line with the error is
CreateObject("xlmagic.xlmagicclass.1_0")
Thanks.
Dim MCLUtil As Object
Dim bModuleInitialized As Boolean
Dim xlmagicclass As Object
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
Sub mymagic()
Dim R1 As Range 'Input value
Dim R2 As Range 'Output range
On Error GoTo Handle_Error
Call InitModule
Set R1 = Range("A2") 'Specify where the input value is.
Set R2 = Range("B2:E5") 'Specify that range for the output to use.
If xlmagicclass Is Nothing Then
Set xlmagicclass = CreateObject("xlmagic.xlmagicclass.1_0")
End If
Call xlmagicclass.mymagic(1, R2, R1)
Exit Sub
Handle_Error:
MsgBox ("Error: " & Format(Err.Number) & " Source: " & Err.Source & " Message: " & Err.Description)
End Sub