Close actxserver file after deleting variables

21 visualizzazioni (ultimi 30 giorni)
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?

Risposta accettata

Bob Thompson
Bob Thompson il 25 Feb 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

Più risposte (0)

Categorie

Scopri di più su Use COM Objects in MATLAB in Help Center e File Exchange

Prodotti


Release

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by