Excel error 429 when running Matlab magic square example from Matlab builder


I was working with the Matlab builder magic square example (can be found in matlab builder users guide) 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. I've got the same error on 2 different computers and different versions of Excel which leads me to believe its has something to do with the way i'm running it.

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

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
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
MsgBox ("Error: " & Format(Err.Number) & " Source: " & Err.Source & " Message: " & Err.Description)
End Sub 
7/24/2010 8:46:03 PM
comp.soft-sys.matlab 211266 articles. 19 followers. lunamoonmoon (257) is leader. Post Follow

0 Replies

Similar Articles

[PageSpeed] 47