MATLAB: What if the excel file is already open. Error using writemtrix (line 175)

errorexcelxlswrite

Error using writemtrix (line 175)
Warning: File not found or permission denied.
I think the problem is that the excel file that I am creating, is already open on my computer. I want to know how to manage this without needing to close the excel file.

Best Answer

The way to handle that without needing to close the excel file, is to stop using writematrix, and instead switch to using ActiveX to tell Excel what you want done with the file. See https://www.mathworks.com/matlabcentral/fileexchange/10465-xlswrite1 to see how that can be done.
That is, it is built into MS Windows that files are automatically locked against reading and writing when they are opened, and the process that opens them needs to deliberately configure to make the files available to other processes. Excel does not do that, so as long as you have the file open in Excel, your only choice is to stop trying to access the file yourself and instead command Excel to do the writing.
Related Question