我正在尝试使用VBA在Excel中创建自定义对象的集合。
我试过这个,但我不明白为什么这是错的:
Dim data As String
Dim myCol As Collection
Set myCol = New Collection
Dim myObj As myClass
Set myObj = PutData(data)
'Error (438) here: Object does not admit this property or method
myCol.Add(myObj)
Public Function PutData(data As String) As myClass
Dim p As New myClass
p.data = data
Set PutData= p
End Function
我如何创建自定义对象集合?
我来自C#,只需初始化List或集合并添加项目,就像这样:
List<MyClass> list = new List<MyClass>();
list.Add(myCustomobject>();