共用方式為


Remove 方法

Dictionary 物件移除索引鍵/專案組。

語法

物件移除 ()

Remove方法語法包含下列部分:

部分 描述
物件 此為必要動作。 一律是 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 支援與意見反應