如何使用 VBA 调试字典中的打印键和值?

Luc*_*683 4 excel vba

我正在使用 vba 并将某些值写入字典。但是,我想看看信息是否已正确传递到字典中。因此,是否可以将字典中的键和值 debug.print 到即时窗口?

我在想这个:

debug.print DicTemp.Items
Run Code Online (Sandbox Code Playgroud)

谢谢!

Vit*_*ata 6

Public Sub TestMe()

    Dim dict As Object
    Set dict = CreateObject("Scripting.Dictionary")
    dict.Add "first", 30
    dict.Add "second", 40
    dict.Add "third", 100

    Dim key As Variant
    For Each key In dict.Keys
        Debug.Print key, dict(key)
    Next key

End Sub
Run Code Online (Sandbox Code Playgroud)

它打印:

first          30 
second         40 
third          100 
Run Code Online (Sandbox Code Playgroud)


Oll*_*lly 5

循环遍历每个字典键,并调试打印:

Dim key As Variant
For Each key In dict.Keys
    Debug.Print key, dict(key)
Next key
Run Code Online (Sandbox Code Playgroud)