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

前端 未结 15 1804
自闭症患者
自闭症患者 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 05:57

    You can shorten the suggested code for this as well as generalize for unexpected errors. Here you go:

    Public Function InCollection(col As Collection, key As String) As Boolean
    
      On Error GoTo incol
      col.Item key
    
    incol:
      InCollection = (Err.Number = 0)
    
    End Function
    

提交回复
热议问题