Share via


Workbook.SheetSelectionChange Event (2007 System)

Occurs when the selection changes on any worksheet. Does not occur if the selection is on a chart sheet.

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

Syntax

'Declaration
Public Event SheetSelectionChange As WorkbookEvents_SheetSelectionChangeEventHandler
'Usage
Dim instance As Workbook 
Dim handler As WorkbookEvents_SheetSelectionChangeEventHandler 

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

Examples

The following code example demonstrates a handler for the SheetSelectionChange event. The event handler displays the sheet name and address of the selected range in the status bar.

This example is for a document-level customization.

Sub ThisWorkbook_SheetSelectionChange(ByVal Sh As Object, _
    ByVal Target As Excel.Range) Handles Me.SheetSelectionChange

    Dim sheet As Excel.Worksheet = CType(Sh, Excel.Worksheet)
    Me.Application.StatusBar = sheet.Name & ":" & _
        Target.Address(ReferenceStyle:=Excel.XlReferenceStyle.xlA1)
End Sub
private void WorkbookSheetSelectionChange()
{
    this.SheetSelectionChange +=
        new Excel.WorkbookEvents_SheetSelectionChangeEventHandler(
        ThisWorkbook_SheetSelectionChange);
}

void ThisWorkbook_SheetSelectionChange(object Sh,
    Excel.Range Target)
{
    Excel.Worksheet sheet = (Excel.Worksheet)Sh;

    this.Application.StatusBar = sheet.Name + ":" +
        Target.get_Address(missing, missing,
        Excel.XlReferenceStyle.xlA1, missing, missing);
}

.NET Framework Security

See Also

Reference

Workbook Class

Workbook Members

Microsoft.Office.Tools.Excel Namespace