共用方式為


WorksheetBase.Move(Object, Object) 方法

定義

將工作表移至活頁簿的其他位置。

public void Move(object before, object after);
member this.Move : obj * obj -> unit
Public Sub Move (Optional before As Object, Optional after As Object)

參數

before
Object

要在其之前放置已移動之工作表的工作表。 如果您指定 After,則無法指定 Before

after
Object

要在其之後放置已移動之工作表的工作表。 如果您指定 Before,則無法指定 After

範例

下列程式代碼範例會 Index 使用 屬性,使用 Move 方法,在將工作表移至活頁簿的最後一個位置之前和之後,顯示目前工作表的索引編號。

此範例適用於檔層級自定義。

private void DisplayIndex()
{
    MessageBox.Show("Before moving, this worksheet is at tab number " +
        this.Index.ToString());

    // Move the worksheet to the last position in the workbook.
    this.Move(missing, 
        Globals.ThisWorkbook.Worksheets[Globals.ThisWorkbook.Worksheets.Count]);

    MessageBox.Show("After moving, this worksheet is at tab number " +
        this.Index.ToString());
}
Private Sub DisplayIndex()
    MsgBox("Before moving, this worksheet is at tab number " & _
        Me.Index.ToString())

    ' Move the worksheet to the last position in the workbook.
    Me.Move(After:=Globals.ThisWorkbook.Worksheets( _
        Globals.ThisWorkbook.Worksheets.Count))

    MsgBox("After moving, this worksheet is at tab number " & _
        Me.Index.ToString())
End Sub

備註

如果您未指定 BeforeAfter,Microsoft Office Excel 會建立包含移動工作表的新活頁簿。

選擇性參數

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

適用於