XL_file = [pwd '\test.xls'];
[type, sheet_names] = xlsfinfo(XL_file);
Excel = actxserver('Excel.Application');
set(Excel, 'Visible', 0);
set(Excel,'DisplayAlerts',0);
Workbooks = Excel.Workbooks;
Workbook=Workbooks.Open(XL_file);
Sheets = Excel.ActiveWorkBook.Sheets;
index_adjust = 0;
for i = 1:max(size(sheet_names))
inp_prompt = sprintf('Do you want to delete the Worksheet called %s [y/n]?',sheet_names{i});
user_inp = lower(input(inp_prompt,'s'));
switch user_inp
case{'y'}
current_sheet = get(Sheets, 'Item', (i-index_adjust));
invoke(current_sheet, 'Delete')
out_string = sprintf('Worksheet called %s deleted',sheet_names{i});
index_adjust = index_adjust +1;
otherwise
out_string = sprintf('Worksheet called %s ***NOT*** deleted',sheet_names{i});
end
disp(out_string);
disp(' ');
end
Workbook.Save;
Workbooks.Close;
invoke(Excel, 'Quit');
delete(Excel);
Best Answer