xlswrite function works once, then throws error - Error using xlswrite (line 226) Invoke Error, Dispatch Exception: Source: Microsoft Excel Description: Add method of Workbooks class failed

조회 수: 48 (최근 30일)
Hi All
I have a strange problem that has only recently started occurring. When I try to execute xlswrite I get the following error:
Error using xlswrite (line 226)
Invoke Error, Dispatch Exception:
Source: Microsoft Excel
Description: Add method of Workbooks class failed
Help File: xlmain11.chm
Help Context ID: 0
I'm running Windows 10 64 bit, Matlab r2018 64bit and Office 365
I've been using xlswrite within my image analysis GUI for about 2 years and it has always worked fine. This error has only started occuring in the last 2 weeks, and only on the second execution. e.g. I save data to excel fine, open another image for analysis, try to save the data again and this error occurs. This has never happened previously after years of use, and the script has not changed.
I have tried a very simple call outside of the GUI "xlswrite('test.xlsx', 1)" and the error occurs again. If i restart Matlab the function will run properly once, then re-occur.
Any ideas? Thanks
Ryan
  댓글 수: 1
Walter Roberson
Walter Roberson 2021년 5월 31일
I seem to recall that the most common cause of this error was if certain add-ons were enabled in Excel. My memory is prompting me as "especially Fox-It", but my memory is not always right ;-)

댓글을 달려면 로그인하십시오.

채택된 답변

Ryan Stafford
Ryan Stafford 2021년 6월 14일
Thanks Walter and Chidvi for your responses.
I have found that the problem was related to my MS Office user account. It seems when MS had a security issue a few weeks ago, I was automatically logged out of my account, and logged in under a different email address without me noticing. The MS Office programs continued to function normally despite no licence associated with the account I was logged in under. However when I was calling xlswrite through Matlab, Excel was behaving in a restricted manner. Now having logged into the correct account with appropriate licence, it works fine again. Cheers
Ryan

추가 답변 (1개)

Chidvi Modala
Chidvi Modala 2021년 6월 8일
A possible reason for this error can be the COM/ActiveX layer that is started by XLSREAD. In particular, Excel is not able to allocate enough memory when it attempts to copy large amounts of data for transfer into MATLAB, and MATLAB is re-throwing the error in the Command Window.
You may perform the following steps in order to eliminate the error:
  1. This error may occur if a file with macros is saved in Excel 2003 and then used with Excel 2007 or Excel 2010. The issue may be resolved by first opening the file with Excel 2007 or 2010 and re-saving.
  2. Place the Excel file in the local directory. If the file is on a shared network, it could be open in a program or in use by users. A possible workaround would be to change the location of the Excel workbook to a local directory from a mapped network drive.
  3. Run the Disk Cleanup by navigating to Start, type "Disk Cleanup" and remove only the "Temporary files" by checking only that option.

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by