WorkbookBase.SheetSelectionChange Event

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.v4.0.Utilities (in Microsoft.Office.Tools.Excel.v4.0.Utilities.dll)

Syntax

'Declaration
Public Event SheetSelectionChange As WorkbookEvents_SheetSelectionChangeEventHandler
public event WorkbookEvents_SheetSelectionChangeEventHandler SheetSelectionChange

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

WorkbookBase Class

Microsoft.Office.Tools.Excel Namespace