共用方式為


NamedRange.Cut 方法

NamedRange 控制項的內容剪到 [剪貼簿],或貼到指定目的端。

命名空間:  Microsoft.Office.Tools.Excel
組件:  Microsoft.Office.Tools.Excel (在 Microsoft.Office.Tools.Excel.dll 中)

語法

'宣告
Function Cut ( _
    Destination As Object _
) As Object
Object Cut(
    Object Destination
)

參數

  • Destination
    型別:System.Object
    應貼上資料的範圍。如果省略這個引數,則會將該物件剪到 [剪貼簿]。

傳回值

型別:System.Object

備註

選擇性參數

如需選擇性參數的詳細資訊,請參閱Office 方案中的選擇性參數

範例

下列程式碼範例會使用 Find 方法,在 NamedRange 控制項中尋找第一個值為 Seashell 的儲存格。範例接著使用 FindNextFindPrevious 方法,尋找下一個值為 Seashell 的儲存格,然後回到原來的儲存格。最後,這個範例會使用 Cut 方法,剪下具有 Seashell 值之第一個儲存格的內容,並將它貼入儲存格 B1。

這是示範文件層級自訂的範例。

    Private Sub FindValue()
        Me.Range("A1").Value2 = "Barnacle"
        Me.Range("A2").Value2 = "Seashell"
        Me.Range("A3").Value2 = "Star Fish"
        Me.Range("A4").Value2 = "Seashell"
        Me.Range("A5").Value2 = "Clam Shell"

        Dim namedRange1 As Microsoft.Office.Tools.Excel.NamedRange _
            = Me.Controls.AddNamedRange(Me.Range("A1", "A5"), _
            "namedRange1")

        ' Find the first occurrence of "Seashell".
        Dim Range1 As Excel.Range = namedRange1.Find("Seashell", , , _
            Excel.XlLookAt.xlWhole, Excel.XlSearchOrder.xlByColumns, _
            Microsoft.Office.Interop.Excel.XlSearchDirection.xlNext, _
            False, False, )

        ' Find the next occurrence of "Seashell".
        Range1 = namedRange1.FindNext(Range1)

        ' Return to the first occurrence of "Seashell".
        Range1 = namedRange1.FindPrevious(Range1)

        ' Cut the range with the first "Seashell" and copy it to cell B1.
        Dim namedRange2 As Microsoft.Office.Tools.Excel.NamedRange _
            = Me.Controls.AddNamedRange(Range1, "namedRange2")
        namedRange2.Cut(Me.Range("B1"))
    End Sub

private void FindValue()
{
    this.Range["A1"].Value2 = "Barnacle";
    this.Range["A2"].Value2 = "Seashell";
    this.Range["A3"].Value2 = "Star Fish";
    this.Range["A4"].Value2 = "Seashell";
    this.Range["A5"].Value2 = "Clam Shell";

    Microsoft.Office.Tools.Excel.NamedRange namedRange1 =
        this.Controls.AddNamedRange(this.Range["A1", "A5"],
        "namedRange1");

    // Find the first occurrence of "Seashell".
    Excel.Range Range1 = namedRange1.Find("Seashell",
        Excel.XlLookAt.xlWhole, Excel.XlSearchOrder.xlByColumns,
        Microsoft.Office.Interop.Excel.XlSearchDirection.xlNext,
        false);

    // Find the next occurrence of "Seashell".
    Range1 = namedRange1.FindNext(Range1);

    // Return to the first occurrence of "Seashell".
    Range1 = namedRange1.FindPrevious(Range1);

    // Cut the range with the first "Seashell" and copy it to cell B1.
    Microsoft.Office.Tools.Excel.NamedRange namedRange2 =
        this.Controls.AddNamedRange(Range1, "namedRange2");
    namedRange2.Cut(this.Range["B1"]);
}

.NET Framework 安全性

請參閱

參考

NamedRange 介面

Microsoft.Office.Tools.Excel 命名空間