|
Hello,
I would like to figure out how to make Matlab detect and operate on an open session of Microsoft Excel. As for right now, I'm only able to detect if there is a file that is already open. There are many situations when I forget to close my edited Excel file, so I'd like Matlab to discover and operate on my open file. Any ideas on how to do this?
===============================
xls.fname = 'Compliance Table SN267 3-4-09' ;
h = actxserver('Excel.Application');
set(h, 'Visible', 1);
% J:\Lab Data\mcm003\str10314
file = [pwd '\' xls.fname '.xls']
a = dir(pwd) ;
if ~exist(file,'file')
ExcelWorkbook = h.workbooks.Add;
ExcelWorkbook.SaveAs(file)
ExcelWorkbook.Close(false);
end
%Open file
ExcelWorkbook = h.workbooks.Open(file);
if ExcelWorkbook.ReadOnly ~= 0
%This means the file is probably open in another process.
error('MATLAB:LockedFile', 'The file %s is not writable. It may be locked by another process.', file);
end
===============================
Yours
Raj
|