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
This code is working for me but it’s giving prompt so for that you send sendkey “Enter”
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
Try
wb = DirectCast(GetObject(Path),Microsoft.Office.Interop.Excel.Workbook)
Catch ex As Exception
excel = DirectCast(CreateObject(“Excel.Application”), Microsoft.Office.Interop.Excel.Application)
‘wb = excel.Workbooks.Open(Path)’
excel.Visible= True
End Try
ws=CType(wb.Sheets(“”),Microsoft.Office.Interop.Excel.Worksheet)
ws.Activate()
ws.Delete()