2012-08-31 139 views
1

我有一組所有者,每個所有者都有自己的一組機會。VBA將對象傳遞到另一個對象集合

我有兩個類模塊,ClmOpportunity具有一束性質的,和ClmOwner其具有單一的名稱屬性和集合存儲ClmOpportunity對象:

Public name As Variant 
Private opps As New collection 

Public Function addOpportunity(opp As ClmOpportunity) 

    opp.ID = opps.Count + 1 
    opps.Add opp, opps.Count + 1 

End Function 

這些所有者對象也被存儲在集合中在我的主模塊中。當我嘗試使用功能addOpportunity如下圖所示:

Dim item As New ClmOpportunity 

item.name = "test" 

owners.item(overallOwner).addOpportunity (item) 

我得到的錯誤:

"object doesn't support this property or method"

我很新的VBA,我不明白這是爲什麼,我傳遞在ClmOpportunity中,所以它應該沒問題吧?

任何幫助將不勝感激!

回答

6

如果沒有返回值,你不要用括號括...

owners.item(overallOwner).addOpportunity item 

...然後你會得到一個「類型不匹配」錯誤,因爲採集需要一個字符串值作爲密鑰,所以你需要調整你的addOpportunity函數(如果你不打算增加一個返回值,它可能應該是一個Sub)

+0

感謝你的回覆 – Steven

相關問題