Unable to obtain Sheets object in ActiveX control.

6 ビュー (過去 30 日間)
Satoshi Furukawa
Satoshi Furukawa 2024 年 7 月 22 日
コメント済み: Satoshi Furukawa 2024 年 7 月 22 日
 Use the ActiveX control to write values ​​to an Excel file.
objExcel = actxserver('excel.application');
objExcel.Visible = 1;
objExcelFile = objExcel.Workbooks.Open( t_filePath );
objSheet = objExcelFile.Sheets.Item(1);
objSheet.Range(t_range).value = t_outputData;
Error message
Method, property or field 'Sheets' of class 'Interface.000208DA_0000_0000_C000_000000000046' is not recognized. Error: ActiveXExcel (line 4) objSheet = objExcelFile.Sheets.Item(1);
A script that previously worked fine in R2021a now gives an error every time in R2024a.
How can I do ?
Thanks in advance.

回答 (1 件)

Ashutosh Thakur
Ashutosh Thakur 2024 年 7 月 22 日
Hi Satoshi,
It seems like the issue has occurred due to a change in the release. I can suggest some troubleshooting steps that may help you find the root cause. These steps mainly involve adding checks in the code to verify whether particular sections of the code are working correctly. You can also use a debugger for this purpose.
  • First, add a check to see if the ActiveX server is properly initialized and whether the Excel application is running:
objExcel = actxserver('excel.application');
if isempty(objExcel)
error('Failed to start Excel application.');
end
  • Next, check whether the necessary permissions for the workbook and sheets are present with that MATLAB release, and add some programmatic checks:
objExcelFile = objExcel.Workbooks.Open(t_filePath);
if isempty(objExcelFile)
error('Failed to open Excel file.');
end
Using these checks can help you identify the root cause of the issue and focus on those particular aspects. Meanwhile, you can also look into the following example of reading an Excel file using a COM server: https://www.mathworks.com/help/matlab/matlab_external/example-reading-excel-spreadsheet-data.html.
I hope this information is helpful.
  1 件のコメント
Satoshi Furukawa
Satoshi Furukawa 2024 年 7 月 22 日
I appreciate your advice.
This was resolved by updating MATLAB R2024a from Update 4 to Update 5.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeActiveX についてさらに検索

タグ

製品


リリース

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by