Compartilhar via


WorkbookBase.NewSheet Event

Definition

Occurs when a new sheet is created in the workbook.

public:
 event Microsoft::Office::Interop::Excel::WorkbookEvents_NewSheetEventHandler ^ NewSheet;
public event Microsoft.Office.Interop.Excel.WorkbookEvents_NewSheetEventHandler NewSheet;
member this.NewSheet : Microsoft.Office.Interop.Excel.WorkbookEvents_NewSheetEventHandler 
Public Custom Event NewSheet As WorkbookEvents_NewSheetEventHandler 

Event Type

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.

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

Applies to