Borrar filtros
Borrar filtros

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

47 visualizaciones (últimos 30 días)
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
  1 comentario
Walter Roberson
Walter Roberson el 31 de Mayo de 2021
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 ;-)

Iniciar sesión para comentar.

Respuesta aceptada

Ryan Stafford
Ryan Stafford el 14 de Jun. de 2021
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

Más respuestas (1)

Chidvi Modala
Chidvi Modala el 8 de Jun. de 2021
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.




Community Treasure Hunt

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

Start Hunting!

Translated by