From: Carl on
I am writing some code with a fair amount of reading and writing to excel files. While debugging I sometimes have an error while Matlab has an excel session open. The excel file is then locked by matlab and the only way I can find of releasing it is to log out of windows. Is there a better way?

Closing and excel session in the task manager sometimes (but not always) works but this can still be a pain as I have to close down any excel session I have open as I can not differentiate between them.

I have tried selecting "always stop if error" in the debugging tool and typing Excel.Quit from the command window but get an error of "Call was rejected by callee"
From: james bejon on
Not quite sure of your problem here, but do you always make Excel visible when creating an instance of it in Matlab, e.g.

xlAPP = actxserver('Excel.Application');
xlAPP.Visible = 1;

Alternatively, you might want to try using a command like

try
% If there's an EXISTING INSTANCE of EXCEL, then use it
xlAPP = actxGetRunningServer('Excel.Application');

catch
% Otherwise, create a NEW INSTANCE
xlAPP = actxserver('Excel.Application');
end

in order to stop Matlab creating new instances of Excel all the time.
From: james bejon on
(P.S. The reason behind my first suggestion is that if you always keep Excel instances visible you should be able to shut them manually rather than having to shut Windows down)
From: Thomas Britton on
If all else fails...

You can generally find the excel process in your task manager which you can then force close. I think this unlocks the excel file for writing....
From: Carl on
Thanks James, that is perfect.

While I want the version of excel to be invisible in the final version making it visible is perfect for while I am developing it.

On a related issue is there any help available to handling excel within Matlab. So far a I just used other people's code but I am sure I could get my code to run faster by adapting it.

For example xlswrite1 is fine for writing lots of variables int oa single spreadsheet, but I am wirting to several. Currently I do this by invoking excel several times, It must be possble (and faster) after saving a file to close it and open another, instead of quitting excel and invoking it again. I just can't find the correct syntax.