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 解决方案中的可选参数

适用于