Partilhar via


Evento NamedRange.Deselected

Ocorre quando a seleção é movida a NamedRange o controle para uma área fora da NamedRange de controle.

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

Sintaxe

'Declaração
Event Deselected As DocEvents_SelectionChangeEventHandler
event DocEvents_SelectionChangeEventHandler Deselected

Comentários

Este evento é gerado somente quando o NamedRange controle tem foco e, em seguida, o foco é transferido longe do NamedRange de controle.

Exemplos

O exemplo de código a seguir demonstra um manipulador para o Deselected evento que exibe o endereço da célula que a seleção é transferida para.

Esta versão é para uma personalização em nível de documento.

Private deselectedRange As Microsoft.Office.Tools.Excel.NamedRange

Private Sub DeselectRange()
    deselectedRange = Me.Controls.AddNamedRange( _
        Me.Range("B1", "D4"), "deselectedRange")
    deselectedRange.Select()
    AddHandler Me.deselectedRange.Deselected, _
        AddressOf deselectedRange_Deselected
End Sub


Sub deselectedRange_Deselected(ByVal Target As Excel.Range)
    Dim targetRange As String = Target.Address(, , _
        Excel.XlReferenceStyle.xlA1, , )

    MessageBox.Show("The NamedRange control was deselected." & _
        " Selection transferred to " & Me.Name & ":" & _
        targetRange & ".")
End Sub
Microsoft.Office.Tools.Excel.NamedRange deselectedRange;
private void DeselectRange()
{
    deselectedRange = this.Controls.AddNamedRange(
        this.Range["B1", "D4"], "deselectedRange");
    deselectedRange.Select();
    this.deselectedRange.Deselected += new
        Microsoft.Office.Interop.Excel.
        DocEvents_SelectionChangeEventHandler(
        deselectedRange_Deselected);
}

void deselectedRange_Deselected(Excel.Range Target)
{
    string targetRange = Target.get_Address(missing, missing,
        Excel.XlReferenceStyle.xlA1, missing, missing);

    MessageBox.Show("The NamedRange control was deselected." +
        " Selection transferred to " + this.Name + ":" + 
        targetRange + ".");
}

Esta versão é um suplemento em nível de aplicativo.

Private deselectedRange As NamedRange

Private Sub DeselectRange()

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

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

    deselectedRange = vstoWorksheet.Controls.AddNamedRange( _
        vstoWorksheet.Range("B1", "D4"), "deselectedRange")
    deselectedRange.Select()
    AddHandler Me.deselectedRange.Deselected, _
        AddressOf deselectedRange_Deselected
End Sub


Sub deselectedRange_Deselected(ByVal Target As Excel.Range)
    Dim targetRange As String = Target.Address(, , _
        Excel.XlReferenceStyle.xlA1, , )

    System.Windows.Forms.MessageBox.Show( _
        "The NamedRange control was deselected." & _
        " Selection transferred to " & _
        Me.Application.ActiveWorkbook.Worksheets(1).Name & ":" & _
        targetRange & ".")
End Sub
NamedRange deselectedRange;
private void DeselectRange()
{
    Worksheet vstoWorksheet =
        Globals.Factory.GetVstoObject(this.Application.ActiveWorkbook.Worksheets[1]);
    deselectedRange = vstoWorksheet.Controls.AddNamedRange(
        vstoWorksheet.Range["B1", "D4"], "deselectedRange");
    deselectedRange.Select();
    deselectedRange.Deselected += new
        Excel.DocEvents_SelectionChangeEventHandler(
        deselectedRange_Deselected);
}

void deselectedRange_Deselected(Excel.Range Target)
{
    string targetRange = 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("The NamedRange control was deselected." +
        " Selection transferred to " +
        nativeWorksheet.Name + ":" +
        targetRange + ".");
}

Segurança do .NET Framework

Consulte também

Referência

NamedRange Interface

Namespace Microsoft.Office.Tools.Excel