MATLAB: How to use two different versions of MATLAB Compiler Runtime with VBA code for MATLAB Builder for Excel

differentMATLAB Builder EXMATLAB Compilermcrmultiplerun timeversion

I want to use two different versions of the MATLAB Compiler Runtime (MCR) in my application that uses a component or add-in built with MATLAB Builder for Excel.
When I try to do so, I get the following error message:
Error: -2147023782 (8007045a)
Source: VBAProject
Message: Automation error A dynamic link library (DLL) initialization routine failed.

Best Answer

It is not possible to use add-ins that were compiled with different versions of MATLAB Builder for Excel from within the same application; however they can be accessed from separate applications.
In order for your add-ins to be accessed from separate applications, you will need to make sure that both versions of MATLAB or MATLAB Compiler Runtime (MCR) are on the path, and that both the components have been registered on the machine (via regsvr32/mwregsvr).
You must also register mwcomutil.dll and mwcommgr.dll for each version of MATLAB or MCR you are using. To learn more about registering components, refer to the following documentation:
In the VBA code, you can invoke the version-specific mwcomutil.dll by using the syntax
Set MCLUtil = CreateObject("MWComUtil.MWUtil7.4") ' To use version 7.4
or the version-independent DLL using
Set MCLUtil = CreateObject("MWComUtil.MWUtil") '<---can end MWUtil with 7.4 or 7.2 or appropriate version