我還在學習VBA和問心無愧我有一個集合對象這麼多問題我想不通。錯誤添加項目到VBA/VB6收藏
我有一個功能,增加了自定義對象(我創建了一個非常簡單的類來存儲一些數據),做典型的「讀取數據,創建對象表示,它粘成收藏」之類的東西。
如果我嘗試添加一個「鑰匙」 bag.add呼叫我得到一個「編譯錯誤的預期:=」消息。
如果我不把它似乎已經工作,然後當我運行它說,這個項目「編譯錯誤。參數不可選」,並強調了「getRevColumns =包」線。
我不能爲我的生活出問心無愧是怎麼回事!我懷疑我的包初始化有什麼問題? PS:columnMap是我的自定義類的名稱。
Function getRevColumns() As Collection
Dim rng As Range
Dim i As Integer
Dim bag As Collection
Dim opManCol As Integer, siebelCol As Integer
Dim opManColName As String, siebelColName As String
Dim itm As columnMap
Set bag = New Collection
Set rng = shSiebelMap.UsedRange.Columns(5)
i = 1
For i = 1 To rng.Rows.count
If StrComp(UCase(rng.Cells(i).value), "Y") = 0 Then
opManCol = rng.Rows(i).OffSet(0, -2).value
opManColName = rng.Rows(i).OffSet(0, -4)
siebelCol = rng.Rows(i).OffSet(0, -1).value
siebelColName = rng.Rows(i).OffSet(0, -3)
Set itm = New columnMap
itm.opManColName = opManColName
itm.opManColNumber = opManCol
itm.siebelColName = siebelColName
itm.siebelColNumber = siebelCol
'WHY DOESN'T IT WORK!''
bag.Add (itm)
'MsgBox "opMan Col: " & opManColName & " : " & opManCol & ". Siebel Col: " & siebelColName & " : " & siebelCol'
End If
Next i
getRevColumns = bag
End Function
是否有可能您發佈類「columnMap」也? – hol 2010-07-30 08:07:16