Compartir a través de


NamedRange.Copy(Object) Method

Definition

Copies the contents of the NamedRange control to the specified range or to the Clipboard.

public object Copy (object Destination);
abstract member Copy : obj -> obj
Public Function Copy (Optional Destination As Object) As Object

Parameters

Destination
Object

Specifies the new range to which the contents of the NamedRange control will be copied. If this argument is omitted, Microsoft Office Excel copies the range to the Clipboard.

Returns

Examples

The following code example uses the Copy method to copy the contents of a NamedRange control named NamedRange1 to the Clipboard, and then uses the PasteSpecial method to paste these contents into a NamedRange control named NamedRange2. The Operation parameter is set to xlPasteSpecialOperationAdd so that the content of each cell in NamedRange1 is added to the corresponding cell in NamedRange2.

This example is for a document-level customization.

private void CopyAndPasteSpecialRange()
{
    Microsoft.Office.Tools.Excel.NamedRange namedRange1 =
        this.Controls.AddNamedRange(this.Range["A1", "A3"],
        "namedRange1");
    namedRange1.Value2 = 22;

    Microsoft.Office.Tools.Excel.NamedRange namedRange2 =
        this.Controls.AddNamedRange(this.Range["C1", "C3"],
        "namedRange2");
    namedRange2.Value2 = 5;

    // Copy the contents of namedRange1 to the clipboard, and then
    // paste the contents into namedRange2, adding each to
    // the value in namedRange2.
    namedRange1.Copy();
    namedRange2.PasteSpecial(Excel.XlPasteType.xlPasteAll,
        Excel.XlPasteSpecialOperation.xlPasteSpecialOperationAdd,
        false,
        false);
}
Private Sub CopyAndPasteSpecialRange()
    Dim namedRange1 As Microsoft.Office.Tools.Excel.NamedRange _
        = Me.Controls.AddNamedRange(Me.Range("A1", "A3"), _
        "namedRange1")
    namedRange1.Value2 = 22

    Dim namedRange2 As Microsoft.Office.Tools.Excel.NamedRange _
        = Me.Controls.AddNamedRange(Me.Range("C1", "C3"), _
        "namedRange2")
    namedRange2.Value2 = 5

    ' Copy the contents of namedRange1 to the clipboard, and then
    ' paste the contents into namedRange2, adding each value to
    ' the value in namedRange2.
    namedRange1.Copy()
    namedRange2.PasteSpecial(Excel.XlPasteType.xlPasteAll, _
    Excel.XlPasteSpecialOperation.xlPasteSpecialOperationAdd, _
    False, False)
End Sub

Remarks

Optional Parameters

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

Applies to