Compartilhar via


NamedRange.Selected Event

Definition

Occurs when the NamedRange control is selected.

public:
 event Microsoft::Office::Interop::Excel::DocEvents_SelectionChangeEventHandler ^ Selected;
event Microsoft.Office.Interop.Excel.DocEvents_SelectionChangeEventHandler Selected;
member this.Selected : Microsoft.Office.Interop.Excel.DocEvents_SelectionChangeEventHandler 
Event Selected As DocEvents_SelectionChangeEventHandler 

Event Type

Examples

The following code example demonstrates a handler for the Selected 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 selectedEventRange;
private void DisplaySelectedRange()
{
    selectedEventRange = this.Controls.AddNamedRange(
        this.Range["B1", "E5"], "selectedEventRange");
    this.selectedEventRange.Selected += new 
        Microsoft.Office.Interop.Excel.
        DocEvents_SelectionChangeEventHandler(
        selectedEventRange_Selected);
}

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

    MessageBox.Show(this.Name + ": " + selectedRange + 
        " was selected.");
}
Private selectedEventRange As Microsoft.Office.Tools.Excel.NamedRange

Private Sub DisplaySelectedRange()
    selectedEventRange = Me.Controls.AddNamedRange( _
        Me.Range("B1", "E5"), "selectedEventRange")
    AddHandler Me.selectedEventRange.Selected, _
        AddressOf selectedEventRange_Selected
End Sub


Sub selectedEventRange_Selected(ByVal Target As _
    Microsoft.Office.Interop.Excel.Range)
    Dim selectedRange As String = Target.Address(, , _
        Excel.XlReferenceStyle.xlA1, , )

    MessageBox.Show(Me.Name & ": " & selectedRange & _
        " was selected.")
End Sub

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

Remarks

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

Applies to