我需要以下帮助。我制作了一个名为 CMpos 的类模块:
Public secId As String
然后在一个模块中,以下代码运行良好:
Sub testclass()
rijaantal_LenDump = Application.CountA(Sheets("Len_Dump").Range("A:A"))
kolomaantal_LenDump = Application.CountA(Sheets("Len_Dump").Range("1:1"))
Sheets("Len_Dump").Select
positions = Sheets("Len_Dump").Range(Cells(1, 1), Cells(rijaantal_LenDump, kolomaantal_LenDump))
kolomSecID = 8
Dim isc As New Collection
For i = 1 To rijaantal_LenDump
Set psecs = New CMpos
psecs.secId = CStr(positions(i, 8))
If Not Exists(isc, psecs.secId) Then isc.Add psecs, psecs.secId
Next i
Debug.Print isc.Count
MsgBox isc(8).secId
End Sub
现在我想从另一个 sub 访问类 Moldule 中的值,但是在这里我在 MsgBox isc(8).secId (type mismatch) 行上得到一个错误。我在一个单独的模块中使用 Public isc As Collection 行创建了一个全局变量。
Sub hjhk()
Call testclass
Dim isc As CMpos
Set isc = New Collection
MsgBox isc(8).secId
End Sub
我究竟做错了什么?
谢谢阿米尔