以前可能有人问过这个问题,但我似乎找不到...
我有一个我创建的类和该类的每个对象的集合,当我将这些对象添加到我的集合中时,我没有给每个项目一个键,而是让 VBA 自动执行此操作。
下面的代码似乎对我不起作用......
ediData.StyleCollection.Add StoreStyleData(Range("A" & i & ":M" & i)), Before:=0
这个也试过了,也不行!
ediData.StyleCollection.Add StoreStyleData(Range("A" & i & ":M" & i)), Before:=1
问题:
如何将项目添加到集合的开头而不是结尾?如果我不能这样做,我如何从结尾而不是开头循环遍历一个集合?
编辑:
下面我已经包含了函数StoreStyleData
Private Function StoreStyleData(rng As Range) As cPOStyle
Set StoreStyleData = New cPOStyle
With rng
StoreStyleData.XRef = .Cells(1).value
StoreStyleData.Season = .Cells(2).value
StoreStyleData.Style = .Cells(3).value
StoreStyleData.Color = .Cells(4).value
StoreStyleData.Size = .Cells(5).value
StoreStyleData.RetailPrice = .Cells(6).value
StoreStyleData.Category = .Cells(8).value
StoreStyleData.PO850Price = .Cells(9).value
StoreStyleData.XRefPrice = .Cells(10).value
StoreStyleData.Units = .Cells(11).value
StoreStyleData.SubTotal = .Cells(12).value
StoreStyleData.Description = .Cells(13).value
End With
End Function
类内收藏
''''''''''''''''''''''
' StyleCollection Property
''''''''''''''''''''''
Public Property Get StyleCollection() As Collection
If pStyleCollection Is Nothing Then Set pStyleCollection = New Collection
Set StyleCollection = pStyleCollection
End Property
Public Property Let StyleCollection(value As Collection)
Set pStyleCollection = value
End Property