Delete excel sheets

Hi all,
My query is how to delete an excel sheet in an excel I have 5sheets i need to delete sheet 2,3 and 4. I am using classic version.

Please help me thanks in advance

@hanviprebday

  1. Inside the “Excel Application Scope,” add a “Invoke VBA” activity.

  2. In the properties of the “Invoke VBA” activity, write the following VB.NET code to delete the sheets:
    Sub DeleteSheets()
    Dim xlApp As Object
    Dim xlWorkBook As Object
    Dim xlWorkSheet As Object

    xlApp = CreateObject(“Excel.Application”)
    xlWorkBook = xlApp.Workbooks.Open(“path_to_your_excel_file.xlsx”)

    Try
    xlWorkBook.Worksheets(“Sheet2”).Delete()
    xlWorkBook.Worksheets(“Sheet3”).Delete()
    xlWorkBook.Worksheets(“Sheet4”).Delete()
    Catch ex As Exception
    ’ Handle any exceptions here if necessary
    End Try

    xlWorkBook.Save()
    xlWorkBook.Close()
    xlApp.Quit()
    End Sub

Hi @hanviprebday

Check the below video for better reference to delete the sheet in classic activities.

Hope it helps!!

1 Like

Hi @hanviprebday

Try this

or


Sub DeleteSheets()
    On Error Resume Next
    Application.DisplayAlerts = False
    ThisWorkbook.Sheets("Sheet2").Delete
    ThisWorkbook.Sheets("Sheet3").Delete
    ThisWorkbook.Sheets("Sheet4").Delete
    Application.DisplayAlerts = True
End Sub

Regards,

Use

  1. Delete Sheet Activity
  2. Use Macro
Sub vba_delete_sheet()
Sheets("Data").Delete
End Sub

Regards,

Prasanth Kumar Manivannan
Battlebots!!

Hi @hanviprebday

Please try this

I hope it helps!!

Thank you for helping me

@hanviprebday

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