WorksheetBase.Copy Method (Object, Object)


Copies the worksheet to another location in the workbook.

Namespace:   Microsoft.Office.Tools.Excel
Assembly:  Microsoft.Office.Tools.Excel.v4.0.Utilities (in Microsoft.Office.Tools.Excel.v4.0.Utilities.dll)

public void Copy(
	object before,
	object after


Type: System.Object

The sheet before which the copied sheet will be placed. You cannot specify Before if you specify After.

Type: System.Object

The sheet after which the copied sheet will be placed. You cannot specify After if you specify Before.

The new worksheet is a Microsoft.Office.Interop.Excel.Worksheet object and does not have the code or data binding capability that worksheet host items have.

If you do not specify either Before or After, Microsoft Office Excel creates a new workbook that contains the copied sheet.

For information on optional parameters, see Optional Parameters in Office Solutions.

The following code example uses the Copy method to create copies of the current worksheet before Sheet1 and after Sheet3. The example uses the InnerObject property to access the underlying Microsoft.Office.Interop.Excel.Worksheet for Sheet1 and Sheet3.

This example is for a document-level customization.

private void CopyWorksheet()
    // Copy this worksheet before Sheet1.

    // Copy this worksheet after Sheet3.
Return to top