Partager via


WorkbookBase.NewSheet Event

Occurs when a new sheet is created 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 Event NewSheet As WorkbookEvents_NewSheetEventHandler
public event WorkbookEvents_NewSheetEventHandler NewSheet

Examples

The following code example demonstrates a handler for the NewSheet event. The event handler moves the new worksheet to the last position in the workbook when a new worksheet is created.

This example is for a document-level customization.

Sub ThisWorkbook_NewSheet(ByVal Sh As Object) _
    Handles Me.NewSheet

    Dim newSheet As Excel.Worksheet = CType(Sh, Excel.Worksheet)
    newSheet.Move(After:=Me.Sheets(Me.Sheets.Count))
End Sub
private void WorkbookNewSheet()
{
    this.NewSheet +=
        new Excel.WorkbookEvents_NewSheetEventHandler(
        ThisWorkbook_NewSheet);
}

void ThisWorkbook_NewSheet(object Sh)
{
    Excel.Worksheet newSheet = (Excel.Worksheet)Sh;
    newSheet.Move( this.Sheets[this.Sheets.Count]);
}

.NET Framework Security

See Also

Reference

WorkbookBase Class

Microsoft.Office.Tools.Excel Namespace