gpt4 book ai didi

arrays - 是否可以将字典添加到 Excel VBA 中的数组?

转载 作者:行者123 更新时间:2023-12-04 21:16:38 24 4
gpt4 key购买 nike

我试图弄清楚这是否有可能就excel的能力而言。在我正在尝试做的事情中考虑以下代码:

Dim some_text, split_text() As String
Dim some_array_dict() As String 'This is the array to store the dictionaries
Dim some_dict As Dictionary 'The dictionaries that I'll be storing in the array above

ReDim some_array_dict(y) As String 'y is previously defined as an integer

For i = 0 To y - 1
Set some_dict = New Dictionary

some_text = some_array(2, i)
split_text = Split(some_text, " ")

For j = 0 To UBound(split_text)
some_dict.Add split_text(j), 1
Next j

some_array_dict(i) = some_dict 'Issue

Debug.Print some_array_dict(i) 'For debugging purposes
Next i
以下是给我错误的代码行:
some_array_dict(i) = some_dict
有人能帮忙吗?

最佳答案

数组被声明为错误类型,需要使用 Set分配对象时

Sub Tester()

Dim arr_dict() As Object, x As Long

ReDim arr_dict(1 To 3)
For x = 1 To 3

Set arr_dict(x) = CreateObject("scripting.dictionary")

With arr_dict(x)
.Add "hello", 1
.Add "there", 2
End With

Next x

End Sub

关于arrays - 是否可以将字典添加到 Excel VBA 中的数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24315623/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com