'********************************************************************************************************** ' Name: joinCollections ' Author: mielk | 2012-03-12 ' ' Comment: Joins up to 30 collections into one larger collection. ' ' Parameters: ' collections() Collections to be merged into larger collection. ' This parameter is of a ParamArray type, so it is possible to pass any number of ' collection to be joined (up to 30). ' All non-collection parameters are ignored. ' ' Returns: ' Collection Collection that contains all the items from the subcollections passed to this ' function. ' * Items in the result collection can be duplicated. ' * Items are added to the result collection without key, even if they are stored ' with key in their original collection. ' ' ' --- Changes log ----------------------------------------------------------------------------------------- ' 2013-04-26 mielk Method created. '********************************************************************************************************** Public Function joinCollections(ParamArray collections() As Variant) As VBA.Collection Const METHOD_NAME As String = "joinCollections" '------------------------------------------------------------------------------------------------------ Dim subcollection As Variant Dim item As Variant '------------------------------------------------------------------------------------------------------ 'Initialize result variable with empty Collection. Set joinCollections = New VBA.Collection 'Iterate through all the given subcollections. --------------------------------------| For Each subcollection In collections '| '| 'Check if an item currently processed in this loop is a collection. '| If TypeOf subcollection Is Collection Then '| '| 'If [subcollection] is a collection, iterate through all its ------------| '| 'items and add them to the result Collection [joinCollections]. '| '| For Each item In subcollection '| '| Call joinCollections.add(item) '| '| Next item '| '| '------------------------------------------------------------------------| '| '| End If '| '| Next subcollection '| '------------------------------------------------------------------------------------| End Function