Delete sheet from excel

Hi,
I want to delete an excel sheet from the file. And no, I don’t want to use the modern excel activity. Any vba code would work in my case.

hi @SunnyJha

please use the below code.

Application.DisplayAlerts = False

Activeworkbook.Sheets(“Data”).Delete

Application.DisplayAlerts = True

you can activate the workbook you want to delete the sheet or you can use thisworkbook specify the workbook name inside bracket.

or you can refer the below invoke VBA activity method.

  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 ObjectxlApp = 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 TryxlWorkBook.Save()
    xlWorkBook.Close()
    xlApp.Quit()
    End Sub

refer the below video for your reference.

hope it helps!!!

Hi @SunnyJha

Try this

File1.txt (192 Bytes)

Cheers!!

1 Like

@SunnyJha

Please refer the below link:

Hi @SunnyJha

You can also use Balareva Excel activities, install this package
image

& use this activity

Hope this helps :slight_smile:

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