我正在写一个Excel宏,并且我在清除时遇到问题Scripting.Dictionary 对象:
Dim test As Integer
test = CompListDict.Count
CompListDict.RemoveAll
Set CompListDict = Nothing
Set CompListDict = CreateObject("Scripting.Dictionary")
Dim test1 As Integer
test1 = CompListDict.Count
在执行此操作之前,我将项目添加到字典中,然后尝试清除它,但 test1 将等于 test 并等于我添加的对象的 nr 。
我究竟做错了什么 ?
谢谢你!
如果我在工作站上运行以下宏,它就会起作用:
Set compListDict = CreateObject("Scripting.Dictionary")
compListDict.Add 1, "Test"
Dim test As Integer
test = compListDict.Count
compListDict.RemoveAll
Set compListDict = Nothing
Set compListDict = CreateObject("Scripting.Dictionary")
Dim test1 As Integer
test1 = compListDict.Count
运行后,test1等于0,test等于1。
确保您已启用 Option Explicit,并且变量名称中没有任何拼写错误。
另外,请确保您没有“On Error Resume Next”语句,因为它会隐藏代码中的错误。尝试将“On Error Goto 0”放在代码片段之前,以便 Excel 显示任何错误消息。
由于您将变量值设置为 Nothing,并为其分配一个新的字典对象,因此它不可能保留以前存储的值。
我也尝试运行以下代码,它也给出了相同的结果:
Set compListDict = CreateObject("Scripting.Dictionary")
compListDict.Add 1, "Test"
Dim test As Integer
test = compListDict.Count
compListDict.RemoveAll
Dim test1 As Integer
test1 = compListDict.Count
希望有帮助...
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)