|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
Some code examples in this topic use the this or Me keyword or the
Themethod deletes a specified worksheet. If the worksheet is created at run time, you must access it through the Microsoft Office Excel 2003 collection; otherwise you can access the directly.
The worksheet object can be one of two types:
Microsoft.Office.Tools.Excel.Worksheet host items are created at design time. For more information on host items, see.
Native Excel object.
Excelobjects are created at run time.
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
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.