0
如何將集合添加到object.property中?它不斷給我一個錯誤。我究竟做錯了什麼? 我想獲得一個樹狀結構,我的意思是一個屬性(例如值)內將是具有與集合另一個對象的集合......Vba將集合添加到對象屬性
Option Explicit
Public name As String
Public value As Variant
Public ValueType As String
Public valueHelp As Collection
Function addColl()
Dim i As Long
For i = 1 To 5
Dim nextCollection As Collection
Set nextCollection = New Collection
Dim obj1 As JsonElement
Set obj1 = New JsonElement
obj1.name = "City" & i
obj1.value = "type"
obj1.ValueType = nextCollection
nextCollection.Add obj1
'obj1.valueHelp = nextCollection
'nextCollection.Add nextCollection
Next
End Function
它給你什麼錯誤,以及哪一行是它造成的? – 2014-10-31 14:21:28
如果VALUETYPE是集合然後 「對象變量或與塊變量未設置」,在 obj1.valueType = nextCollection 如果VALUETYPE是一個變量,然後 「數量的參數或無效的屬性賦值錯誤」 – kunmateo 2014-10-31 14:25:46
你嘗試過' Set obj1.ValueType = nextCollection' – kurast 2014-10-31 17:14:50