Share via


Eliminar método

Quita un par clave-elemento de un objeto Dictionary .

Sintaxis

objeto . Quitar (clave)

La sintaxis del método Remove consta de las partes siguientes:

Parte Descripción
object Obligatorio. Siempre es el nombre de un objeto Dictionary.
key Obligatorio. Clave asociada al par clave-elemento que desea quitar del objeto Dictionary .

Comentarios

Se produce un error si el par clave-elemento especificado no existe.

En el código siguiente se muestra el uso del método Remove .

Public Sub Start()

    Dim d As Object
    Set d = CreateObject("Scripting.Dictionary")
    
    d.Add "a", "Athens"
    d.Add "b", "Belgrade"
    d.Add "c", "Cairo"
    
    Debug.Print "Keys, before using Remove."
    PrintKeys d
    
    d.Remove "b"
    
    Debug.Print "Keys, after removing key 'b'."
    PrintKeys d

End Sub

Private Sub PrintKeys(ByVal d As Object)
    
    Dim k As Variant
    For Each k In d.Keys
        Debug.Print k
    Next k
    
End Sub

' The example displays the following output:
' Keys, before using Remove.
' a
' b
' c
' Keys, after removing key 'b'.
' a
' c

Vea también

Soporte técnico y comentarios

¿Tiene preguntas o comentarios sobre VBA para Office o esta documentación? Vea Soporte técnico y comentarios sobre VBA para Office para obtener ayuda sobre las formas en las que puede recibir soporte técnico y enviar comentarios.