How can I determine if an XLS-file is open in Microsoft Excel, without using DDE commands, using MATLAB 7.7 (R2008b)?
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
MathWorks Support Team
am 27 Jun. 2009
Bearbeitet: MathWorks Support Team
am 25 Apr. 2016
I want to check whether an XLS-file is currently open in Microsoft Excel. In the past I used the command:
check_open = ddeinit('Excel',excelfile);
Now, DDEINIT has been deprecated. Is there any other workaround to resolve this issue?
Akzeptierte Antwort
MathWorks Support Team
am 25 Apr. 2016
To check if an XLS-file is open in Microsoft Excel, you may use any of the alternatives below:
1. Using 'ActiveX' commands:
try
%Check if an Excel server is running
ex = actxGetRunningServer('Excel.Application');
catch ME
disp(ME.message)
end
if exist('ex','var')
%Get the names of all open Excel files
wbs = ex.Workbooks;
%List the entire path of all excel workbooks that are currently open
for i = 1:wbs.Count
wbs.Item(i).FullName
end
end
The code above will list all the open .xlsx file.
2. Using 'FOPEN':
[fid msg] = fopen('path\to\excel\file\filename.xls','a');
if fid==-1
disp('The file is already open.')
else
fclose(fid);
disp('If the file did not already exist, it has been created.')
end
In the above code, 'fid' is returned as '-1' if MATLAB was unable to open the file (since file is open in another application). Please note that an empty file will be created if it did not exist in the location specified to FOPEN .
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Spreadsheets finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!