WorksheetBase.Move 方法

将工作表移动到工作簿中的另一个位置。

命名空间:  Microsoft.Office.Tools.Excel
程序集:  Microsoft.Office.Tools.Excel.v4.0.Utilities(在 Microsoft.Office.Tools.Excel.v4.0.Utilities.dll 中)

语法

声明
Public Sub Move ( _
    before As Object, _
    after As Object _
)
public void Move(
    Object before,
    Object after
)

参数

  • before
    类型:System.Object
    移动工作表的放置位置之后的工作表。如果指定 After,则不能指定 Before。
  • after
    类型:System.Object
    移动工作表的放置位置之前的工作表。如果指定 Before,则不能指定 After。

备注

如果既未指定 Before,也未指定 After,则 Microsoft Office Excel 创建一个包含移动工作表的新工作簿。

可选参数

有关可选参数的信息,请参见Office 解决方案中的可选参数

示例

下面的代码示例在通过使用 Move 方法将工作表移动到工作簿中的最后一个位置之前和之后使用 Index 属性来显示当前工作表的索引号。

此示例针对的是文档级自定义项。

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
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());
}

.NET Framework 安全性

请参见

参考

WorksheetBase 类

Microsoft.Office.Tools.Excel 命名空间