To delete a sheet from excel without using human intervention and opening the excel file

You can add a setting to the code to prevent popups and also to ensure the deletion is done in the background:

DeleteWorksheets.xaml (6.6 KB) Test.xlsx (8.8 KB)

Dim xlApp As Microsoft.Office.Interop.Excel.Application
Dim wb As Microsoft.Office.Interop.Excel.Workbook

xlApp = New Microsoft.Office.Interop.Excel.Application
wb = xlApp.Workbooks.Open(filename)

xlApp.DisplayAlerts = False
TryCast(wb.Sheets(sheetname), Microsoft.Office.Interop.Excel.Worksheet).Delete()
xlApp.DisplayAlerts = False
xlApp.Visible = False

wb.Save()
wb.Close()

7 Likes