How do I resolve the automation error in VBA project, "ClassFactory cannot supply requested class" when using MATLAB Compiler SDK R2025b generated Excel add-ins?

I updated a MATLAB Compiler SDK application from MATLAB Runtime R2022a to MATLAB Runtime R2025b. The generated COM component is registered successfully, and I can create the COM objects from PowerShell using
New-Object -ComObject
However, when I attempt to initialize the MATLAB Runtime R2025b from Excel VBA using code similar to the following:
Set MCLUtil = CreateObject("MWComUtil.MWUtil")
Call MCLUtil.MWInitApplication(Application)
Excel reports the following error:
Runtime initialization failed.
Error number: -2147221231
Description: Automation error
ClassFactory cannot supply requested class
Source: VBAProject
 The issue occurs even when using a version-specific ProgID, such as:
Set MCLUtil = CreateObject("MWComUtil.MWUtil25.2")
The COM component and MATLAB Runtime appear to be installed and registered correctly, and the same workflow works when using MATLAB Runtime R2022a.
How can I resolve this error?

 Accepted Answer

This error indicates that Windows COM is unable to locate or instantiate a required COM class during initialization of the MATLAB Runtime R2025b or the generated COM component.
A common cause of this issue is a MATLAB release mismatch between COM components loaded within the same Excel process.
When using COM components or Excel add-ins generated with MATLAB Compiler SDK, all MATLAB-generated components loaded in a single Excel session should be built using the same MATLAB release. Mixing components compiled from different MATLAB releases can cause COM initialization failures such as the one you are observing.
To resolve the issue, verify that all MATLAB-generated COM components and Excel add-ins loaded by Excel were compiled using the same MATLAB release.
If components from different releases must be used, choose one of the following approaches:
  1. Close and restart Excel before loading a component built with a different MATLAB release.
  2. Launch a separate Excel process for each MATLAB release.
  3. Recompile all MATLAB-generated components using the same release

More Answers (0)

Categories

Products

Release

R2006b

Community Treasure Hunt

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

Start Hunting!