Compartilhar via


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)

Syntax

'Declaration
Public Sub Copy ( _
    before As Object, _
    after As Object _
)
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.

Remarks

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.

Examples

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 Sub CopyWorksheet()
    ' Copy this worksheet before Sheet1. 
    Me.Copy(Globals.Sheet1.InnerObject)

    ' Copy this worksheet after Sheet3. 
    Me.Copy(After:=Globals.Sheet3.InnerObject)
End Sub
private void CopyWorksheet()
{
    // Copy this worksheet before Sheet1. 
    this.Copy(Globals.Sheet1.InnerObject);

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

.NET Framework Security

See Also

Reference

WorksheetBase Class

Microsoft.Office.Tools.Excel Namespace

Other Resources

Host Items and Host Controls Overview