How do I obtain a list of all currently open workbooks through an Excel ACTXSERVER object in MATLAB 7.8 (R2009a)?

16 views (last 30 days)
I am connecting to an instance of Excel using the ACTXSERVER or ACTXGETRUNNINGSERVER functions, opening a number of files, and reading data from them. Using the Excel COM API methods, I would like to be able to get a list of all Excel files that are currently open in the program.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
Assuming you have created an ACTXSERVER or ACTXGETRUNNINGSERVER object named 'e' in MATLAB that connects to a COM/ActiveX instance of Excel:
% Opens a new server instance of Excel
e = actxserver('excel.application')
% Obtains handle to existing running instance of Excel
e = actxGetRunningServer('excel.application');
the following code demonstrates how to obtain a list of all open Excel files (i.e., workbooks) by invoking Excel's COM API methods:
% Obtain handle to collection of open Workbooks in Excel
w = e.Workbooks;
% Get number of open Workbooks
numWorkbooks = w.Count;
% Query name of each open Workbook
for i = 1:numWorkbooks
openFiles{i} = w.Item(i).Name;
end
% Display names of open Workbooks
openFiles{:}

More Answers (0)

Products


Release

R2009a

Community Treasure Hunt

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

Start Hunting!