Hi,
I am running the below code to delete emtpy sheets with MATLAB 2020a and Excel 2016. When doing so Excel asks me to sign into my account. Is there away to do this automatically?
excelFileName = [file_name,'.xlsx'];sheetName = 'Sheet'; % EN: Sheet, DE: Tabelle, etc. (Lang. dependent)
% Open Excel file.
objExcel = actxserver('Excel.Application');objExcel.Workbooks.Open(fullfile(excelFilePath, excelFileName)); % Full path is necessary!
% Delete sheets.
try % Throws an error if the sheets do not exist.
objExcel.ActiveWorkbook.Worksheets.Item([sheetName '1']).Delete; objExcel.ActiveWorkbook.Worksheets.Item([sheetName '2']).Delete; objExcel.ActiveWorkbook.Worksheets.Item([sheetName '3']).Delete;catch ; % Do nothing.
end% Save, close and clean up.
objExcel.ActiveWorkbook.Save;objExcel.ActiveWorkbook.Close;objExcel.Quit;objExcel.delete;
I only have this problem one specifc pc. On all other PCs its fine. The Excel Add-in for matlab is also active in excel.
Thanks for the help!
Chris
Best Answer