Close actxserver file after deleting variables

18 visualizaciones (últimos 30 días)
Bob Thompson
Bob Thompson el 8 de Feb. de 2021
Respondida: Bob Thompson el 25 de Feb. de 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?

Respuesta aceptada

Bob Thompson
Bob Thompson el 25 de Feb. de 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

Más respuestas (0)

Categorías

Más información sobre Use COM Objects in MATLAB en Help Center y File Exchange.

Productos


Versión

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by