VBA将类添加到集合中

Log*_*gan 12 collections vba

我有一个名为Holding的类模块.其中有几个公共变量.我的代码是这样的:

Dim holdings as Collection
Dim h as Holding

Set holdings = new Collection

For i = 1 to last
    Set h = new Holding

    h.x = y
    '... etc

    holdings.Add(h)
Next i
Run Code Online (Sandbox Code Playgroud)

这给了我错误的"对象不支持这个属性或方法" holdings.Add(h),但我看到的每个地方都给出了如何实现这个的确切示例.我错过了什么?

GSe*_*erg 19

删除括号.

holdings.Add h
Run Code Online (Sandbox Code Playgroud)

否则,您尝试向集合添加Holding实例的默认属性的值,并且它没有默认属性.