Delete a Sheet from a Excel

Hi
Trying to delete a sheet from a Excel which contains Data,I am deleting the sheet through vb.net,here when the sheet is empty it is deleting,when it is non empty the sheet is not get deleted,

please suggest me with this
please verify code i have used

Dim excel As Microsoft.Office.Interop.Excel.Application
Dim wb As Microsoft.Office.Interop.Excel.Workbook
Dim ws As Microsoft.Office.Interop.Excel.Worksheet
Dim rng As Microsoft.Office.Interop.Excel.Range
excel = New Microsoft.Office.Interop.Excel.ApplicationClass
wb = excel.Workbooks.Open(newfile)

ws=CType(wb.Sheets(“Sheet2”),Microsoft.Office.Interop.Excel.Worksheet)
ws.Delete()
wb.Save()
wb.Close()
excel.Quit()

Thanks & Regards,
A Manohar

Hi @Manohar1,

Please use the Delete Sheet activity.

To get that activity, please install this package: BalaReva.Excel.Activities
image

Hope this helps.
Thanks and regards,
Despi

5 Likes

Hi @Jan_Brian_Despi

Thanks ,Its working…

1 Like

Good to hear that!
Feel free to approach me anytime :slight_smile:

2 Likes

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