how to delete a sheet in excel using uipath commands and save the file…
thank you…
i am able to delete it… but once i reopen the file the sheet still exists…how to over come that…??
what is the option for it… Ctrl S??
use Send hot Key activity
Alt + h then d and then ctrl + S
Regards,
Arivu
Alt F+S helps in saving the file
or ALT 1… helps in saving an excel file
Great then use the key to save the file.
Regards,
Arivu
Just in case anyone else comes upon this question, an easier way to do this is to just use the invoke code activity and use VB.NET to remove it.
You’ll need to add the Microsoft.Office.Interop.Excel reference if you don’t already have it.
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(filepath)
xlApp.DisplayAlerts = False
TryCast(wb.Sheets(sheetname), Microsoft.Office.Interop.Excel.Worksheet).Delete()
xlApp.DisplayAlerts = True
wb.Save()
wb.Close()
This uses 2 string input arguments. filepath is the full file path of the workbook, including the extension. sheetname is the name of the worksheet you’d like to delete. This is the visible name of the worksheet NOT the VBA worksheet name defined in the VBA editing window.
I commonly need to delete just a single sheet, and just include it in a uipath loop if I need to remove more than one sheet. However, it’d be easy enough to modify the code yourself to loop through an array of strings that’s passed in for sheetname, or to loop through based on sheet index. If you do go the index route, make sure you delete from last to first because the index of later items will change if you start deleting from the beginning.
I am trying your code to code to delete sheet from excel file and getting error like: Can’t find Interop type that matches embedded type ‘Microsoft.Office.Interop.Excel.Application’.
Where I need to add this reference. Could you please help me in this.
Hi,
You may install a package → AdvanceExcel. The package included an activity named “Delete Worksheet”.
Remember to mark the answer as solution.

Hi,
You can execute below mentioned VBA method to delete worksheet
Sub DeleteWorksheet(Sheetname As String)
Application.DisplayAlerts = False
Sheets(Sheetname).Delete
Application.DisplayAlerts = True
End Sub
Thanks,
Madhura
hi @shrganes
Here is a detailed article on that
# How To Delete Sheets From An Excel File Programmatically – In UiPath
Regards,