如何使用VBA调试字典中的打印键和值?
问题描述:
我正在使用vba,并且已将某些值写入字典.但是,我想查看信息是否已正确传递到字典中.因此,是否可以将字典中的键和值调试到当前窗口?
I am using vba and have written certain values into the dictionary. However, I would like to see if information has been passed into the dictionary correctly. Hence, is it possible to debug.print keys and values in a dictionary to the immediate window?
我在想这个:
debug.print DicTemp.Items
谢谢!
答
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
它打印:
first 30
second 40
third 100