VBA向集合添加类 [英] VBA Adding a class to a collection

查看:188
本文介绍了VBA向集合添加类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类模块叫做。在它是几个公共变量。我的代码是这样的:

 将集合作为集合
Dim h as Holding

Set holdings = new Collection

For i = 1 to last
设置h = new控制

hx = y
'... etc

holdings.Add(h)
下一页i

对象不支持这个属性或方法在 holdings.Add(h)行,但无处不在,我看,它给出了如何实现这一确切的例子。


$ b

$ p $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ p> holdings.Add h

否则您正尝试添加到集合 Holding 实例的默认属性的值,并且没有默认属性。


I have a class module called Holding. In it are several public variables. My code is this:

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

This gives me error "object doesnt support this property or method" on the holdings.Add(h) line, but everywhere I look, it gives this exact example of how to achieve this. What am I missing?

解决方案

Remove the parentheses.

holdings.Add h

Otherwise you are trying to add to the collection the value of the default property of your Holding instance, and it doesn't have a default property.

这篇关于VBA向集合添加类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆