MATLAB: I have two versions of MATLAB installed on the computer, why am I unable to use MATLAB Builder EX with one version and not the other

compilerMATLAB Builder EXnewerolder

I have MATLAB Builder EX 1.2.10 (R2008a) installed on my computer. I was able to use it until I installed MATLAB Builder EX 1.2.12 (R2009a) on my computer. Now, I can only compile and create working DLLs from the newest version.
If I use 'deploytool' to create a DLL in MATLAB Builder EX 1.2.10 (R2008a), there seem to be no issues when I compile. However, when I try to run this DLL in Excel, I receive the following error message:
VBAProject Message: Automation error A dynamic link library (DLL) initialization routine failed.
I have registered my project dll as well as mwcommgr.dll and mwcomutil.dll from MATLAB 7.6 (R2008a) using regsvr32 at the DOS command prompt.

Best Answer

This automation error is caused due to the system environment variable setting for the PATH variable.
When a file or collection of files is compiled in MATLAB using 'deploytool', the version of MATLAB that you are compiling the application on must be before all other versions of MATLAB in the system path. Otherwise, the application will try to look for the wrong libraries when it is running the deployed application and this may result in errors.
Specifically, this error was caused because an incorrect version of mbuild was being used during compilation. This causes the Builder EX generated COM dll to link against a different mclmcrrt7x.dll. Installing MATLAB 7.8 (R2009a) adds $MATLABROOT9a/bin on the path ahead of the MATLAB 7.6 (R2008a) path and since mbuild.bat resides in $MATLABROOT/bin folder, the MATLAB 7.8 (R2009a) mbuild is called by mcc.
To workaround this issue, please enter the following command at the MATLAB command prompt:
setenv('PATH',(matlabroot) '\bin;' getenv('PATH'))
Verify that this worked by using the following command:
getenv('PATH')
You should see $MATLABROOT_8a/bin first on the path.
Some important caveats to note:
1.) You must exit out of ALL Microsoft applications before the path updates will take effect. This includes Microsoft Outlook, Word, Power Point, Excel, etc.
2.) You must restart MATLAB and recompile your application after this is done. Double check that your path settings are correct by typing "getenv('path')" at the MATLAB command prompt in order to ensure that the path is in the correct order.
Please refer to the Related Solution below to check how to change your System PATH.