Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determining whether an object is a member of a collection in VBA

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.

like image 708
inglesp Avatar asked Sep 26 '08 04:09

inglesp


People also ask

What is a collection object in VBA?

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.

What is a member in VBA?

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.

How do you check if a value is in an array VBA?

Use Match() function in excel VBA to check whether the value exists in an array.

How do you clear a collection in VBA?

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.


Video Answer


1 Answers

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 
like image 115
Vadim Avatar answered Sep 20 '22 11:09

Vadim