How to: Delete Worksheets from Workbooks
TOC
Collapse the table of content
Expand the table of content
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

How to: Delete Worksheets from Workbooks

NoteNote

Some code examples in this topic use the this or Me keyword or the Globals class in a way that is specific to document-level customizations, or they rely on features of document-level customizations such as host controls. These examples can be compiled only if you have the required applications installed. For more information, see Features Available by Product Combination.

The Delete method deletes a specified worksheet. If the worksheet is created at run time, you must access it through the Microsoft Office Excel 2003 Sheets collection; otherwise you can access the Worksheet directly.

The worksheet object can be one of two types:

Using Host Items

The following code deletes a worksheet from a workbook by referencing the worksheet host item directly.

To delete a worksheet from a workbook using a host item

  • Call the Delete method of Sheet1.

    Globals.Sheet1.Delete();
    
    

Using Excel Objects

The following code deletes a worksheet from a workbook by referencing the sheet through the index number of the Sheets collection. This code assumes that a new worksheet was created programmatically.

To delete a worksheet from a workbook using the Excel Sheets collection

  • Call the Delete method of the Sheets collection.

    ((Excel.Worksheet)this.Application.ActiveWorkbook.Sheets[4]).Delete();
    
    

See Also

Show:
© 2016 Microsoft