2014-10-31 44 views
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 
+0

它给你什么错误,以及哪一行是它造成的? – 2014-10-31 14:21:28

+1

如果VALUETYPE是集合然后 “对象变量或与块变量未设置”,在 obj1.valueType = nextCollection 如果VALUETYPE是一个变量,然后 “数量的参数或无效的属性赋值错误” – kunmateo 2014-10-31 14:25:46

+1

你尝试过' Set obj1.ValueType = nextCollection' – kurast 2014-10-31 17:14:50

回答

1

我猜你只需要替换此行:

obj1.ValueType = nextCollection 

这一行:

Set obj1.ValueType = nextCollection 

,因为你想存储(集合型)的值属性的对象类型不能隐式调用Set关键字,因为它与字符串或整数。