This documentation is archived and is not being maintained.

How to: Delete Worksheets from Workbooks

Applies to

The information in this topic applies only to the specified Visual Studio Tools for Office projects and versions of Microsoft Office.

Project type

  • Document-level projects

  • Application-level projects

Microsoft Office version

  • Excel 2003

  • Excel 2007

For more information, see Features Available by Application and Project Type.

You can delete any worksheet in a workbook. To delete a worksheet, use the worksheet host item or access the worksheet by using the sheets collection of the workbook.

If the worksheet was added at design-time in a document-level customization, use the Delete method to delete a specified worksheet. The following code deletes a worksheet from a workbook by referencing the worksheet host item directly.

To delete a worksheet by using a worksheet host item

Access worksheets through the Microsoft Office Excel Sheets collection in the following cases:

  • You want to delete a worksheet in an application-level add-in.

  • The worksheet that you want to delete was created at run time in a document-level customization.

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 by using the Sheets collection of the Excel workbook

  • Call the Delete method of the Sheets collection.