How can I determine if an XLS-file is open in Microsoft Excel, without using DDE commands, using MATLAB 7.7 (R2008b)?

6 ビュー (過去 30 日間)
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?

採用された回答

MathWorks Support Team
MathWorks Support Team 2016 年 4 月 25 日
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 件)

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

製品


リリース

R2008b

Community Treasure Hunt

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

Start Hunting!

Translated by