从 Dictionary 对象中删除键/项对。
语法
对象。删除 (密钥)
Remove 方法语法具有以下部分:
| Part | 说明 | 
|---|---|
| object | 必填。 始终为 Dictionary 对象的名称。 | 
| key | 必填。 与要从 Dictionary 对象中删除的键/项对关联的键。 | 
备注
如果指定的键/项对不存在,则会发生错误。
以下代码演示 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
另请参阅
支持和反馈
有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。