Share via


Workbook.NewSheet Event (2007 System)

Occurs when a new sheet is created in the workbook.

Namespace:  Microsoft.Office.Tools.Excel
Assembly:  Microsoft.Office.Tools.Excel.v9.0 (in Microsoft.Office.Tools.Excel.v9.0.dll)

Syntax

'Declaration
Public Event NewSheet As WorkbookEvents_NewSheetEventHandler
'Usage
Dim instance As Workbook 
Dim handler As WorkbookEvents_NewSheetEventHandler 

AddHandler instance.NewSheet, handler
public event WorkbookEvents_NewSheetEventHandler NewSheet
public:
 event WorkbookEvents_NewSheetEventHandler^ NewSheet {
    void add (WorkbookEvents_NewSheetEventHandler^ value);
    void remove (WorkbookEvents_NewSheetEventHandler^ value);
}
JScript does not support events.

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(missing, this.Sheets[this.Sheets.Count]);
}

.NET Framework Security

See Also

Reference

Workbook Class

Workbook Members

Microsoft.Office.Tools.Excel Namespace