How can I determine if an XLS-file is open in Microsoft Excel, without using DDE commands, using MATLAB 7.7 (R2008b)?
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
MathWorks Support Team
el 27 de Jun. de 2009
Editada: MathWorks Support Team
el 25 de Abr. de 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?
Respuesta aceptada
MathWorks Support Team
el 25 de Abr. de 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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Spreadsheets en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!