Share via


Worksheet.SelectionChange Event (2007 System)

Occurs when the selection changes on a worksheet.

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

Syntax

'Declaration
Public Event SelectionChange As DocEvents_SelectionChangeEventHandler
'Usage
Dim instance As Worksheet 
Dim handler As DocEvents_SelectionChangeEventHandler 

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

Examples

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

This example is for a document-level customization.

Sub Worksheet1_SelectionChange(ByVal Target As Excel.Range) _
    Handles Me.SelectionChange
    Me.Application.StatusBar = Me.Name & ":" & _
        Target.Address(ReferenceStyle:=Excel.XlReferenceStyle.xlA1)
End Sub
private void WorksheetSelectionChange()
{
    this.SelectionChange += 
        new Excel.DocEvents_SelectionChangeEventHandler(
        Worksheet1_SelectionChange);
}

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

.NET Framework Security

See Also

Reference

Worksheet Class

Worksheet Members

Microsoft.Office.Tools.Excel Namespace