WorksheetBase.Move Method
Moves the worksheet to another location in the workbook.
Namespace: Microsoft.Office.Tools.Excel
Assembly: Microsoft.Office.Tools.Excel.v4.0.Utilities (in Microsoft.Office.Tools.Excel.v4.0.Utilities.dll)
Syntax
'Declaration
Public Sub Move ( _
before As Object, _
after As Object _
)
public void Move(
Object before,
Object after
)
Parameters
before
Type: System.ObjectThe sheet before which the moved sheet will be placed. You cannot specify Before if you specify After.
after
Type: System.ObjectThe sheet after which the moved sheet will be placed. You cannot specify After if you specify Before.
Remarks
If you do not specify either Before or After, Microsoft Office Excel creates a new workbook that contains the moved sheet.
Optional Parameters
For information on optional parameters, see Optional Parameters in Office Solutions.
Examples
The following code example uses the Index property to display the index number of the current worksheet before and after moving the worksheet to the last position in the workbook by using the Move method.
This example is for a document-level customization.
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 Security
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.