共用方式為


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 命名空間