How can I fix the "Unable to Start MATLAB. Please register MATLAB Software as a COM Server." error?
18 ビュー (過去 30 日間)
古いコメントを表示
MathWorks Support Team
2020 年 10 月 13 日
編集済み: MathWorks Support Team
2025 年 7 月 24 日
I am trying to connect to MATLAB using Spreadsheet Link using R2020b. I have just upgraded from R2020a where it was working and now, when I try opening MATLAB from Excel, I am getting following error
"Unable to Start MATLAB. Please register MATLAB Software as a COM Server."
When I tried going back to R2020a, it stopped working there too.
採用された回答
MathWorks Support Team
2025 年 7 月 23 日
編集済み: MathWorks Support Team
2025 年 7 月 24 日
Before following the steps below, this issue might be caused by security. The following steps should be attempted if a security issue is an unlikely cause:
1. Since Spreadsheet Link is trying to open an instance of R2020b, it is important first check if a new instance of MATLAB can be opened from MATLAB as a COM server. Regardless of the version of MATLAB from which it is called, in the Command Window, executing
>> actxserver('matlab.desktop.application')
should open a new instance of MATLAB, and ideally R2020b. If a new instance of the desktop version of R2020b does not open, check what is returned by:
>> comserver('query')
In the two paths printed under User and Administrator should have R2020b in them. By default it might be:
User: 'C:\Program Files\MATLAB\R2020b\bin\win64\matlab.exe'
Administrator: 'C:\Program Files\MATLAB\R2020b\bin\win64\MATLAB.exe'
If this is not the case, close MATLAB, re-open MATLAB R2020b as an administrator, and execute
>> comserver('unregister', 'User', 'all')
>> comserver('unregister')
which will unregister MATLAB as a COM server. Close all instances of MATLAB and relaunch R2020b as an administrator. This will ensure that only the active MATLAB session of R2020b will be re-registered as a COM server. Then, execute:
>> regmatlabserver
>> comserver('query')
User: ''
Administrator: 'C:\Program Files\MATLAB\R2020b\bin\win64\MATLAB.exe'
2. Assuming there are no other instances of MATLAB running, calling
>> actxserver('matlab.desktop.application')
from either R2020a or R2020b (while still in administrator mode) will launch R2020b. Since MATLAB can now be launched as a COM server from MATLAB, it can also be done from Excel.
3. In a new Excel workbook, create a new VBA module by going to the Developer tab in the ribbon and clicking on the "Visual Basic" item. In there, create a new module under "Sheet1" and paste in the following code:
Dim matlabtest As Object
Sub testmatlab()
Set matlab = Nothing
Set matlabtest = CreateObject("Matlab.Desktop.Application")
MsgBox ("Check MATLAB")
End Sub
Before running this, make sure that all instances of MATLAB are closed again. This short VBA subroutine tries to create an instance of MATLAB using "CreateObject" which is the simplest way to start MATLAB as a COM server from Excel. If the subroutine fails to run, there is likely a security issue where a third party application or firewall is preventing Excel from running any scripts. If this succeeds and a new instance of R2020b opens, then Spreadsheet Link should be working as well.
If the above steps do not resolve the issue, you may try the following workaround:
Sometimes, the problem occurs because your Excel spreadsheet is set to use the wrong version of MATLAB, which can prevent MATLAB from starting correctly. This may happen if you have multiple versions of MATLAB installed or if the spreadsheet is configured to use an incorrect version. To address this, follow these steps:
1. Shut down all instances of MATLAB and excel.
2. Open Excel, click on the MATLAB icon, and select Preferences.
3. Replace the value in the “MATLAB program id” field with the ID corresponding to your specific MATLAB version (you can find the appropriate program ID for your MATLAB version in the MATLAB Runtime versions documentation).
4. Since you are using R2020b, your program ID should be 9.9 (please enter it exactly as shown, without quotes).
5. Save your changes, then click the MATLAB icon in Excel again and try to start MATLAB.
6. Spreadsheet Link should now start a new MATLAB session.
Please note that if you have multiple MATLAB versions installed, Spreadsheet Link will always use the last registered version. If you attempt to connect to an already running MATLAB session that is not the last registered version, Spreadsheet Link will start a new session instead of connecting to the existing one. More information is available in the MATLAB Start and Stop Spreadsheet Link documentation.
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Use COM Objects in MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!