我还在学习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