NamedRange.Selected 事件

当选择 NamedRange 控件时发生。

命名空间:  Microsoft.Office.Tools.Excel
程序集:  Microsoft.Office.Tools.Excel(在 Microsoft.Office.Tools.Excel.dll 中)

语法

声明
Event Selected As DocEvents_SelectionChangeEventHandler
event DocEvents_SelectionChangeEventHandler Selected

备注

当所选内容更改为 NamedRange 控件时,将引发此事件。

示例

下面的代码示例演示 Selected 事件的处理程序,该事件显示在 NamedRange 中选择的单元格的地址。

此版本针对的是文档级自定义项。

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

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

此版本针对的是应用程序级外接程序。

.NET Framework 安全性

请参见

参考

NamedRange 接口

Microsoft.Office.Tools.Excel 命名空间