Hi guys, I've written a code with alot of loops and in each loop there the xlsread or xlswrite commands. I've installed Excel 2010 and I'm not using it when I'm running the code . These are the errors:
It may be locked by another process.
or
Error registering event(s), Advise failed
Error in registerevent>addevent (line 148)
list(m+1) = handle.listener(h, eventname, {@comeventcallback, eventhandler});
Error in registerevent (line 94)
addevent(h, event, eventhandler);
Error in xlsreadCOM (line 11)
Excel.registerevent({'WorkbookActivate', @WorkbookActivateHandler});
Error in xlsread (line 230)
[numericData, textData, rawData, customOutput] = xlsreadCOM(file, sheet, range,
Excel, customFun);
Please help me out. thanks in advance.
I'll make it an answer.
I think you can, see the link:
http://www.mathworks.se/matlabcentral/answers/46161#comment_95151
Cheers!
My guess is that you already have Excel open with that workbook. If something strange happened, like you used ActiveX and hid Excel but never closed it, then Excel may still be running even if you can't see it in the task bar. In that case, if you're using Windows, type control-shift-Esc to bring up the process list, and kill Excel.
4 Comments
Direct link to this comment:
http://mathworks.com/matlabcentral/answers/46291#comment_95172
Please post the complete error messages. The command, which causes the error is required also.
Direct link to this comment:
http://mathworks.com/matlabcentral/answers/46291#comment_95185
It's happening because I'm using too much xlsread or xlswrite functions in the code, But why is that?! Thanks
Direct link to this comment:
http://mathworks.com/matlabcentral/answers/46291#comment_95189
Every time you launch xlswrite/read, excel is launched, processes your commands and closes. That is heavy business. It is hard to guess what might cause your problem without knowing the structure of your code, what kind of data you have, etc... So for others to help, more information is needed. A recommendation on my part would be to look at memory comsumption when your process is running, if it spikes then maybe you have too many calls to that function, but that's just a wild guess.
Direct link to this comment:
http://mathworks.com/matlabcentral/answers/46291#comment_95198
Dear Guerrero, Your guess is correct. I use the xlsread/write to read/write vectors from/into the Excel file too many times. Is there no way to tell MATLAB to open the file and close it whenever the code is finished?