- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm having trouble with adding documents to a collection. For some reason, when I try to add part documents to a collection like this (VBA):
Dim clsSRs As Collection
Set clsSRs = New Collection
Dim oRefDocSR As Document
For Each oRefDocSR In ThisApplication.ActiveDocument.ReferencedDocuments
If UsefulFunctions.GetiPropertyByName(oRefDocSR, "Description").Value Like "*SIDE RAIL*" And _
oRefDocSR.DocumentType = kPartDocumentObject Then
clsSRs.Add (oRefDocSR)
End If
Next
the items in the collection are of type Variant/Long, so I cannot access the documents' properties (because they're not objects). Note that UsefulFunctions.GetiPropertyByName is simply a function that returns a document's property and accepts the document object and property name as parameters; though this isn't really relevant to the problem.
However, when I try to add the same documents in the same manner, but to an array like this:
Dim i As Long
Dim oCVs() As PartDocument
Dim oRefDoc As Document
For Each oRefDoc In ThisApplication.ActiveDocument.ReferencedDocuments
If UsefulFunctions.GetiPropertyByName(oRefDoc, "Description").Value Like "*SIDE RAIL*" And _
oRefDoc.DocumentType = kPartDocumentObject Then
i = i + 1
ReDim Preserve oCVs(1 To i)
Set oCVs(i) = oRefDoc
End If
Next
the items in the array are of type PartDocument/PartDocument and I can now access their properties. This can be see in the watches window screenshot below:
I would like to use collections as I've read they're more versatile and adding objects to an array and redimensioning as I did above is messy and inefficient. Can anyone provide some feedback? I've searched online and in these forums, but haven't found a solution.
Solved! Go to Solution.