Close actxserver file after deleting variables

24 views (last 30 days)
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?

Accepted Answer

Bob Thompson
Bob Thompson on 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

More Answers (0)




Community Treasure Hunt

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

Start Hunting!

Translated by