VBA Looping through a Collection VBA Looping through a Collection vba vba

VBA Looping through a Collection


The collection that's returned by SelectManyFiles is not returning a collection of objects. It's probably returning a collection of Strings, but that's just a guess. Change your sub to this

Sub Main()Dim Drawing As VariantDim Drawings As CollectionSet Drawings = SelectManyFiles()For Each Drawing In Drawings    Debug.Print TypeName(Drawing)Next DrawingEnd Sub

And see what the Debug.Print gives you. If it's any scalar (string, long, double, Boolean, etc), then you need to declare Drawing as Variant. Only if all of the collection items are objects can you use Object.


TRY

    FOR X = 1 TO DRAWING.COUNT        'STUFF HAPPENS    NEXT X