Partilhar via


Evento NamedRange.SelectionChange (sistema de 2007)

Ocorre quando a seleção dentro de NamedRange controle alterações.

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

Sintaxe

Public Event SelectionChange As DocEvents_SelectionChangeEventHandler

Dim instance As NamedRange
Dim handler As DocEvents_SelectionChangeEventHandler

AddHandler instance.SelectionChange, handler
public event DocEvents_SelectionChangeEventHandler SelectionChange

Comentários

Este evento é gerado quando a seleção é alterada para ou dentro de NamedRange controle.

Exemplos

O exemplo de código a seguir demonstra um manipulador para o SelectionChange evento que exibe o endereço de uma célula selecionada no NamedRange.

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

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

PrivateSub DisplaySelectionChange()
    selectionChangeRange = Me.Controls.AddNamedRange( _
        Me.Range("A1", "E5"), "selectionChangeRange")
    AddHandlerMe.selectionChangeRange.SelectionChange, _
        AddressOf selectionChangeRange_SelectionChange
EndSubSub selectionChangeRange_SelectionChange(ByVal Target As _
    Microsoft.Office.Interop.Excel.Range)
    Dim selectedRange AsString = Target.Address(, , _
        Excel.XlReferenceStyle.xlA1, , )

    MessageBox.Show(Me.Name & ": " & selectedRange & _
        " raised the SelectionChange event.")
EndSub
Microsoft.Office.Tools.Excel.NamedRange selectionChangeRange;
privatevoid DisplaySelectionChange()
{
    selectionChangeRange = this.Controls.AddNamedRange(
        this.Range["A1", "E5"], "selectionChangeRange");
    this.selectionChangeRange.SelectionChange += new 
        Microsoft.Office.Interop.Excel.
        DocEvents_SelectionChangeEventHandler(
        selectionChangeRange_SelectionChange);
}

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

    MessageBox.Show(this.Name + ": " + selectedRange + 
        " raised the SelectionChange event.");
}

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

Private selectionChangeRange As NamedRange

PrivateSub DisplaySelectionChange()
    Dim vstoWorksheet As Worksheet = CType( _
        Me.Application.ActiveWorkbook.Worksheets(1),  _
        Excel.Worksheet).GetVstoObject()
    selectionChangeRange = vstoWorksheet.Controls.AddNamedRange( _
        vstoWorksheet.Range("A1", "E5"), "selectionChangeRange")
    AddHandlerMe.selectionChangeRange.SelectionChange, _
        AddressOf selectionChangeRange_SelectionChange
EndSubSub selectionChangeRange_SelectionChange(ByVal Target As  _
    Microsoft.Office.Interop.Excel.Range)
    Dim selectedRange AsString = Target.Address(, , _
        Excel.XlReferenceStyle.xlA1, , )

    System.Windows.Forms.MessageBox.Show( _
        Me.Application.ActiveWorkbook.Worksheets(1).Name & _
        ": " & selectedRange & " raised the SelectionChange event.")
EndSub
NamedRange selectionChangeRange;
privatevoid DisplaySelectionChange()
{
    Worksheet vstoWorksheet = ((Excel.Worksheet)
        this.Application.ActiveWorkbook.Worksheets[1]).GetVstoObject();
    selectionChangeRange = vstoWorksheet.Controls.AddNamedRange(
        vstoWorksheet.Range["A1", "E5"], "selectionChangeRange");
    this.selectionChangeRange.SelectionChange += new
        Excel.DocEvents_SelectionChangeEventHandler(
        selectionChangeRange_SelectionChange);
}

void selectionChangeRange_SelectionChange(
    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 +
        " raised the SelectionChange event.");
}

Permissões

Consulte também

Referência

NamedRange Classe

Membros NamedRange

Namespace Microsoft.Office.Tools.Excel

Date

History

Motivo

Julho de 2008

Adicionado a uma versão do código de exemplo para um suplemento em nível de aplicativo.

Alteração de recurso do SP1.