用戶定義的類對象中的每個循環中的代碼是在這裏,你會得到一個運行時錯誤「424」爲每個語句與在VBA
Public Sub test()
Dim a As clsTest
Dim dic As Dictionary
Dim tmpObj As clsTest
Set dic = New Dictionary
Set a = New clsTest
dic.Add "1", a
dic.Add "2", New clsTest
dic.Add "3", New clsTest
For Each tmpObj In dic.Items '--<< error: Run-time error '424' Object required
Debug.Print tmpObj.i
Next tmpObj
Stop
End Sub
是的我一直在使用變體選項,但它失去了智能感知,所以在開發時我必須不斷改變從變體到clsTest的類型,並在運行時返回。 – Chris
更新了我的代碼。 tmpObj可以以這種方式強制輸入到您的自定義類中,並且您具有對值的智能感知。 – InContext