Close actxserver file after deleting variables

18 次查看(过去 30 天)
I have a script that opens an excel workbook in the actxserver so it can create plots for some data. I have been modifying the code recently and sometimes for get to manually close my excel file when the script runs into an error. This wouldn't be a problem except my script clears all of the variables at the beginning, so if I run it again it removes the variables from the workspace and I can't use the manual commands any more.
Anybody know how I can force the connection to close? Preferrably without close out of MATLAB?

采纳的回答

Bob Thompson
Bob Thompson 2021-2-25
For the record, I never did find a way to do this, instead I put a bit of code at the beginning of my script to look for an open version of the ActXServer, and close it.
if exist('xl','var') % Check if the server has been opened at all
if length(class(xl)) > 9 & class(xl) == 'COM.Excel_Application' % Check if excel is in use
xls.Save; % Saves the open workbook
xl.Quit; % Exits excel
xl.delete; % Deletes the variable
end
end

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Use COM Objects in MATLAB 的更多信息

产品


版本

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by