Unable to obtain Sheets object in ActiveX control.

8 views (last 30 days)
 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.

Answers (1)

Ashutosh Thakur
Ashutosh Thakur on 22 Jul 2024
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 Comment
Satoshi Furukawa
Satoshi Furukawa on 22 Jul 2024
I appreciate your advice.
This was resolved by updating MATLAB R2024a from Update 4 to Update 5.

Sign in to comment.

Products


Release

R2024a

Community Treasure Hunt

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

Start Hunting!