2011-06-13 75 views
11

我有一個名爲Holding的類模塊。它有幾個公共變量。我的代碼是這樣的:VBA向集合中添加類

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)線,但到處看,它給出瞭如何實現這個這個確切的例子。我錯過了什麼?

回答

18

刪除括號。

holdings.Add h 

否則你想添加到收藏您Holding實例的默認屬性的值,它不具有默認屬性。