Expand Minimize

WorksheetBase.Copy Method

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
)

Parameters

before
Type: System.Object

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

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.

Optional Parameters

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. 
    this.Copy(Globals.Sheet1.InnerObject);

    // Copy this worksheet after Sheet3. 
    this.Copy(Globals.Sheet3.InnerObject);
}

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2015 Microsoft