Hi All, How to delete excel sheet using VBA or VBScript.
My sheet name and file name changes every time i want to pass arguments for that. can anyone suggest me how to do.
i tried few VBA and VBS scripts but i’m getting error.
Use invoke code activity and create one argument for sheet name to delete. Please find the below code. don’t forget to include the Microsoft.Office.Interop.Excel namespace. please try and let us know. thanks.
Dim excel As Microsoft.Office.Interop.Excel.Application
Dim wb1 As Microsoft.Office.Interop.Excel.Workbook
Dim ws1 As Microsoft.Office.Interop.Excel.Worksheet
excel = New Microsoft.Office.Interop.Excel.ApplicationClass
wb1 = excel.Workbooks.Open(WorkBookPath)
ws1 = CType(wb1.Sheets(SheetToDelete), Microsoft.Office.Interop.Excel.Worksheet)
wb1.Application.DisplayAlerts = False
ws1.Delete
wb1.Application.DisplayAlerts = True
wb1.Save
wb1.Close
excel.Quit
ws1 = Nothing
wb1 = Nothing
excel = Nothing
GC.Collect