Sdílet prostřednictvím


NamedRange.Selected – událost

Dochází, když NamedRange ovládací prvek.

Obor názvů:  Microsoft.Office.Tools.Excel
Sestavení:  Microsoft.Office.Tools.Excel (v Microsoft.Office.Tools.Excel.dll)

Syntaxe

'Deklarace
Event Selected As DocEvents_SelectionChangeEventHandler
event DocEvents_SelectionChangeEventHandler Selected

Poznámky

Tato událost je aktivována, když se změní na výběr NamedRange řízení.

Příklady

Následující příklad kódu ukazuje obslužnou rutinu pro Selected událost, která zobrazuje adresu buňky vybrané v NamedRange.

Tato verze je přizpůsobení úrovni dokumentu.

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
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(missing, missing,
        Excel.XlReferenceStyle.xlA1, missing, missing);

    MessageBox.Show(this.Name + ": " + selectedRange + 
        " was selected.");
}

Tato verze je aplikace- doplněkúroveň.

Private selectedEventRange As NamedRange

Private Sub DisplaySelectedRange()

    Dim NativeWorksheet As Microsoft.Office.Interop.Excel.Worksheet =
        Globals.ThisAddIn.Application.ActiveSheet

    Dim vstoWorksheet As Microsoft.Office.Tools.Excel.Worksheet =
            Globals.Factory.GetVstoObject(NativeWorksheet)

    selectedEventRange = vstoWorksheet.Controls.AddNamedRange( _
        vstoWorksheet.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, , )

    System.Windows.Forms.MessageBox.Show( _
        Me.Application.ActiveWorkbook.Worksheets(1).Name & _
        ": " & selectedRange & " was selected.")
End Sub
NamedRange selectedEventRange;
private void DisplaySelectedRange()
{
    Worksheet vstoWorksheet =
        Globals.Factory.GetVstoObject(this.Application.ActiveWorkbook.Worksheets[1]);
    selectedEventRange = vstoWorksheet.Controls.AddNamedRange(
        vstoWorksheet.Range["B1", "E5"], "selectedEventRange");
    selectedEventRange.Selected += new
        Excel.DocEvents_SelectionChangeEventHandler(
        selectedEventRange_Selected);
}

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

    Excel.Worksheet nativeWorksheet = (Excel.Worksheet)
        this.Application.ActiveWorkbook.Worksheets[1];
    System.Windows.Forms.MessageBox.Show(
        nativeWorksheet.Name + ": " + selectedRange +
        " was selected.");
}

Zabezpečení rozhraní .NET Framework

Viz také

Odkaz

NamedRange Rozhraní

Microsoft.Office.Tools.Excel – obor názvů