Export (0) Print
Expand All

NamedRange.SelectionChange Event

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

Occurs when the selection inside the NamedRange control changes.

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

event DocEvents_SelectionChangeEventHandler SelectionChange

This event is raised when the selection changes to or within the NamedRange control.

The following code example demonstrates a handler for the SelectionChange event that displays the address of a cell that is selected in the NamedRange.

This version is for a document-level customization.

Microsoft.Office.Tools.Excel.NamedRange selectionChangeRange;
private void DisplaySelectionChange()
{
    selectionChangeRange = this.Controls.AddNamedRange(
        this.Range["A1", "E5"], "selectionChangeRange");
    this.selectionChangeRange.SelectionChange += new 
        Microsoft.Office.Interop.Excel.
        DocEvents_SelectionChangeEventHandler(
        selectionChangeRange_SelectionChange);
}

void selectionChangeRange_SelectionChange(
    Microsoft.Office.Interop.Excel.Range Target)
{
    string selectedRange = Target.get_Address(
        Excel.XlReferenceStyle.xlA1);

    MessageBox.Show(this.Name + ": " + selectedRange + 
        " raised the SelectionChange event.");
}

This version is for an application-level add-in.

Show:
© 2014 Microsoft