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 CenterFile Exchange에서 ActiveX에 대해 자세히 알아보기

태그

제품


릴리스

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by