Vba将Collection添加到object属性中

时间:2014-10-31 14:09:36

标签: vba properties

如何将集合添加到object.property中?它一直给我一个错误。我究竟做错了什么? 我想获得一个树结构,我的意思是在一个属性中(例如值)将是一个集合,其中有另一个具有集合的对象...

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

1 个答案:

答案 0 :(得分:1)

我想你只需要替换这一行:

obj1.ValueType = nextCollection

这一行:

Set obj1.ValueType = nextCollection

因为您尝试在(类型Collection)中存储值的属性的对象类型不能像使用字符串或整数一样隐式调用Set关键字。