check if excel file is saved and closed in matlab

You can use the xlsread function to try and open the file. If it is already open, you will get an error message. Here's an example code snippet:

main.m
try
    [~,~,~] = xlsread('path\to\file.xlsx');
catch ME
    if strcmp(ME.identifier,'MATLAB:xlsread:FileOpen')
        disp('Excel file is open');
    else
        rethrow(ME)
    end
end
189 chars
10 lines

This code will try to open the file with xlsread, and if it can't because the file is already open, it will catch the error and display a message saying that the file is open.

If the file is not open and can be opened by xlsread, then it is saved and closed.

related categories

gistlibby LogSnag