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

Hi All,

How to delete a sheet from excel,

Note: considering below points.

  1. We do not have to open Excel.
  2. We do not have to provide Hotkeys
  3. Do not have to use custom activity apart from uipath.
  4. Have used Invoke Code, but it requires human intervention(by using invoke code, Excel provide a pop-up, if user want to delete the sheet permanently. Do not need this pop-up)

Here’s the code, please make necessary changes to avoid the Pop-up.

thank you all plz help.

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()

4 Likes

Thank you,

It is working.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.