VBA将项目添加到SortedList会导致“自动化错误”
为什么以下代码会导致错误:-2146233079(80131509)。
Sub testSortedList()
Dim list
Set list = CreateObject("System.Collections.SortedList")
list.Add 1978340499, "a"
list.Add 1, "b"
End Sub
Why the following code causes an error: -2146233079(80131509).
Sub testSortedList()
Dim list
Set list = CreateObject("System.Collections.SortedList")
list.Add 1978340499, "a"
list.Add 1, "b"
End Sub
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它们的列表的键必须具有相同的数据类型。您添加了两种不同的数据类型,第一种是类型
long
,类型integer
的第二个,这会引发错误消息 *无法比较两个元素...”解决:将
&
附加到1
,这将迫使VBA将您的常数存储为long
:或为键使用变量值:
They keys of the list needs to be of same data type. You add two different data types, the first is of type
Long
, the second of typeInteger
and this throws the error message *failed to compare two elements..."Simplest work around: Append an
&
to the1
, this will force VBA to store your constant as aLong
:Or use variables for your key values: