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

inglesp picture inglesp · Sep 26, 2008 · Viewed 127.7k times · Source

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.

Answer

Vadim picture Vadim · Jun 14, 2009

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