Export (0) Print
Expand All

Worksheet.Copy Method

Copies the worksheet to another location in the workbook.

Namespace: Microsoft.Office.Tools.Excel
Assembly: Microsoft.Office.Tools.Excel (in microsoft.office.tools.excel.dll)

public virtual void Copy (
	[OptionalAttribute] Object Before,
	[OptionalAttribute] Object After
)

Parameters

Before

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

After

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 Microsoft.Office.Tools.Excel.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 Understanding Optional Parameters in COM Interop.

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.

private void CopyWorksheet()
{
    // Copy this worksheet before Sheet1.
    this.Copy(Globals.Sheet1.InnerObject, missing);

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

Show:
© 2014 Microsoft