VBA向集合添加类

13

我有一个名为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

holdings.Add(h)这一行出现"对象不支持此属性或方法"的错误,但无论我看到哪里,都给出了如何实现此操作的确切示例。我错过了什么?

1个回答

24

去掉括号。

holdings.Add h
否则,你试图将你的 Holding 实例的默认属性值添加到集合中,但它没有默认属性。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接