How to delete some specific sheets from an existing excel file using vb.net code?


#1

I was trying the below vb.net code to delete some specific sheets from an excel file but it doesn’t give me the result what I expected. Actually I need to add that vb.net code into ‘Invoke vba’ activity in UiPath. Here I have attached all the snapshots of my work. I’m very new to the vb.net and need a clarification for the below code.

Try

app = New Microsoft.Office.Interop.Excel.ApplicationClass
workbook= app.Workbooks.Open(filePath)
TryCast(workbook.Sheets(sheetName),Worksheet).Delete()
workbook.Save
System.Diagnostics.Process.GetProcessesByName("excel")(0).Kill

Catch ex As Exception

End Try