Training
Module
Build Office Add-ins for Excel - Training
This module walks through development of Office Add-ins for Microsoft Excel.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
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.
Applies to: The information in this topic applies to document-level projects and VSTO Add-in projects for Excel. For more information, see Features available by Office application and project type.
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.
Important
This code runs only in projects that you create by using any of the following project templates:
Excel 2013 Workbook
Excel 2013 Template
Excel 2010 Workbook
Excel 2010 Template
If you want to perform this task in any other type of project, you must add a reference to the Microsoft.Office.Interop.Excel assembly, and then you must use classes from that assembly to open a workbook and delete a worksheet. For more information, see How to: Target Office applications through primary interop assemblies and Excel 2010 primary interop assembly reference.
Call the Delete method of Sheet1
.
Access worksheets through the Microsoft Office Excel Sheets collection in the following cases:
You want to delete a worksheet in a VSTO 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.
Important
If you want to perform this task in any other type of project, you must add a reference to the Microsoft.Office.Interop.Excel assembly, and then you must use classes from that assembly to open a workbook and delete a worksheet. For more information, see How to: Target Office applications through primary interop assemblies and Excel 2010 primary interop assembly reference.
Training
Module
Build Office Add-ins for Excel - Training
This module walks through development of Office Add-ins for Microsoft Excel.