Why do I receive error -2147467259 when trying to run my deployed Excel add-in built with Builder EX?

6 views (last 30 days)
I work on a 64-bit Windows and I created an Excel add-in from my MATLAB code using MATLAB Builder EX 2.3 (R2012b). When I try to run it, I get the following error:
Error: -2147467259 Source: xlmagic.xlmagic.1_0
I notice that, in the VBA code, the MCR is initialized fine, and then the compiled class object is also instantiated fine (CreateObject works). The error occurs when I try to call the deployed function. How do I fix this?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 16 May 2019
Edited: MathWorks Support Team on 15 May 2019
This generally indicates a bitness mismatch issue and can occur if:
1)
If multiple MCR installations (of the same version, different bitness) are present, then the wrong bitness MCR might be picked up. On the system PATH, make sure the appropriate bitness MCR is in front of the other MCR installation paths.
See related solutions below for instructions on setting Windows system path.
2)
If the DLLs are registered with the tool of wrong bitness. To avoid this, make sure the appropriate regsvr32.exe is used to register the DLLs. For 64-bit Windows, there are two versions of this executable, a 64-bit version which is in:
C:\Windows\System32\regsvr32.exe
and the 32-bit version which is in:
C:\Windows\SysWOW64\regsvr32.exe
The 64-bit version is automatically on the path (so calling regsvr32 at the CMD window will call the 64-bit version) so to call the 32-bit version, you must specify the full path. Alternatively, you can utilize the MathWorks provided registration tool at:
<mcrroot>\runtime\<arch>\mwregsvr.exe
where mcrroot is the MCR installation location, such as 'C:\Program Files (x86)\MATLAB\MATLAB Compiler Runtime\v80', and where arch is the OS architecture, such as 'win32' or 'win64'.
3)
Make sure your deployed add-ins are the same version as Excel. For example, if your Excel is 32-bit, then you must compile a 32-bit add-in by using a 32-bit MATLAB.
4)
If the bitness matches for MATLAB and DLL and third-party software (Excel, Access), this same error could potentially be caused by the empty strings in VBA.
Try to initialize strings in VBA to be empty strings, i.e. s="".
For example, the following could cause error:
Dim s as String
Call myMatlabCOMObject.itsMethod(s)
While initializing s to be empty string could potentially fix the error:
Dim s as String: s=""
Call myMatlabCOMObject.itsMethod(s)
The possible cause could be the difference between uninitialized string vs. empty string. For example, those two might be the same in VBA but different in .NET, thus causing error.
The following VBA could could be used to check to ensure that any arrays are specifically set to vbNull:
Function EmptyVarArray2Null(varArray As Variant) As Variant
'Certain interfaces require an Null variant (type vbNull, or no valid data)
'instead of empty (type vbEmpty, or uninitialized), for example the MATLAB
'COM interface when passing unused arrays. This sets an empty array to null.
'If the input is an atomic data type like double, date, int, etc., then the function
'just returns a variant version of the input.
If vartype(varArray) < vbArray Then
Debug.Print "Warning: modutilities.EmptyVarArray2Null only works with arrays. Results may be unreliable."
EmptyVarArray2Null = varArray
Exit Function
End If
If IsNothing(varArray) Then
EmptyVarArray2Null = Null
Else
EmptyVarArray2Null = varArray
End If
End Function

More Answers (0)

Categories

Find more on Excel Add-Ins in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!