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

前端 未结 15 1843
自闭症患者
自闭症患者 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条回答
  •  猫巷女王i
    2020-11-27 06:09

    For the case when key is unused for collection:

    Public Function Contains(col As Collection, thisItem As Variant) As   Boolean
    
      Dim item As Variant
    
      Contains = False
      For Each item In col
        If item = thisItem Then
          Contains = True
          Exit Function
        End If
      Next
    End Function
    

提交回复
热议问题