WorksheetBase.Copy(Object, Object) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Copies the worksheet to another location in the workbook.
public void Copy (object before, object after);
member this.Copy : obj * obj -> unit
Public Sub Copy (Optional before As Object, Optional after As Object)
Parameters
- before
- Object
The sheet before which the copied sheet will be placed. You cannot specify Before
if you specify After
.
- after
- Object
The sheet after which the copied sheet will be placed. You cannot specify After
if you specify Before
.
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 void CopyWorksheet()
{
// Copy this worksheet before Sheet1.
this.Copy(Globals.Sheet1.InnerObject);
// Copy this worksheet after Sheet3.
this.Copy(Globals.Sheet3.InnerObject);
}
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
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.