Close actxserver file after deleting variables

20 vues (au cours des 30 derniers jours)
Bob Thompson
Bob Thompson le 8 Fév 2021
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?

Réponse acceptée

Bob Thompson
Bob Thompson le 25 Fév 2021
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

Plus de réponses (0)

Catégories

En savoir plus sur Use COM Objects in MATLAB dans Help Center et File Exchange

Produits


Version

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by