How to: Programmatically copy worksheets
Applies to: Visual Studio
Visual Studio for Mac
Visual Studio Code
You can create a copy of a worksheet, and insert that worksheet before or after an existing worksheet in the workbook. If you do not specify where to insert the worksheet, Excel creates a new workbook to contain the new worksheet.
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.
Note
Whether you copy the worksheet programmatically, or the end user copies the worksheet manually, there is no code behind the new worksheet and controls on the new worksheet do not function. This is because the newly copied worksheet is a Worksheet object and not a Worksheet host item. Windows Forms controls and host controls can only be added to host items. For more information, see Programmatic limitations of host items and host controls.
To add a copied worksheet to a workbook in a document-level customization
Use the Copy method to copy the first worksheet in the current workbook and place the copy after the third sheet.
To add a copied worksheet to a workbook in a VSTO Add-in
Use the Copy method to copy the first worksheet in the current workbook and place the copy after the third sheet.
See also
- Work with worksheets
- Host items and host controls overview
- How to: Programmatically add new worksheets to workbooks
- How to: Programmatically delete worksheets from workbooks
- How to: Programmatically select worksheets
- Automate Excel by using extended objects
- Global access to objects in Office projects
- Programmatic limitations of host items and host controls
- Optional parameters in Office solutions
Feedback
Submit and view feedback for