error: The object invoked has disconnected from its clients.
Show older comments
As I am running a loop that opens and checks excel files, the loop is forced to stopped with the error:
error: The object invoked has disconnected from its clients.
Can anyone tell me why this error is occurring?
This is my code:
filelist = {data.AllExcelPath};
hassheet = false(size(filelist));
excel = actxserver('Excel.Application');
cleanupobj = onCleanup(@() excel.Quit);
for fileidx = 1:numel(filelist)
try
workbook = excel.Workbooks.Open(filelist{fileidx}, false, true);
end
sheetnames = arrayfun(@(i) workbook.Sheets.Item(i).Name, 1:workbook.Sheets.Count, 'UniformOutput', false);
workbook.Close(false);
if ismember('Cooking_is_fun', sheetnames)
hassheet(fileidx) = true;
end
wantedExcel = filelist(hassheet);
end
It seems that no one has had this error before, and it is very hard to figure out whether it is a problem with my code or VBA or else... Does anyone have a clue why this is happening? Any help/discussion will be greatly appreciated! Thanks!!
Accepted Answer
More Answers (0)
Categories
Find more on Variables in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!