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

前端 未结 15 1789
自闭症患者
自闭症患者 2020-11-27 05:35

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 TableDe

15条回答
  •  [愿得一人]
    2020-11-27 06:08

    I did it like this, a variation on Vadims code but to me a bit more readable:

    ' Returns TRUE if item is already contained in collection, otherwise FALSE
    
    Public Function Contains(col As Collection, item As String) As Boolean
    
        Dim i As Integer
    
        For i = 1 To col.Count
    
        If col.item(i) = item Then
            Contains = True
            Exit Function
        End If
    
        Next i
    
        Contains = False
    
    End Function
    

提交回复
热议问题