How do I determine whether an object is a member of a collection in VBA?
Specifically, I need to find out whether a table definition is a member of the TableDefs
collection.
The Collection object provides a convenient way to refer to a related group of items as a single object. The items, or members, in a collection need only be related by the fact that they exist in the collection. Members of a collection don't have to share the same data type.
Member is the general term for a property, method, enumeration, or constant that belongs to the object. Objects help organize members by grouping them into functional units. Objects are used throughout Visual Basic to organize things. In fact, if you type VBA.
Use Match() function in excel VBA to check whether the value exists in an array.
To remove all items from a collection you can simply set it to nothing. If you set this collection to nothing then it will be set to the state where the “object is not set”. When you add a new item VBA automatically sets the Collection variable to a valid collection.
Isn't it good enough?
Public Function Contains(col As Collection, key As Variant) As Boolean Dim obj As Variant On Error GoTo err Contains = True obj = col(key) Exit Function err: Contains = False End Function
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With