网上找到的资料
======================================================================
This is how you can get a list of properties for an object or determine if a property exists for an object...
1) Add the "TypeLib Information" reference to your project. To do this, click "Project->References..." then select "TypeLib Information" (TLBINF32.DLL) from the reference list.
2) Add the following code to a MODULE:
'-------------------------------------------------------------------------------
Public Enum EPType
ReadableProperties = 2
WriteableProperties = 4
End Enum
Public Function EnumerateProperties(pObject As Object, pType As EPType) As Variant
Dim rArray() As String
Dim iVal As Long
Dim TypeLib As TLI.InterfaceInfo
Dim Prop As TLI.MemberInfo
On Error Resume Next
ReDim rArray(0) As String
Set TypeLib = TLI.InterfaceInfoFromObject(pObject)
For Each Prop In TypeLib.Members
If Prop.InvokeKind = pType Then
iVal = UBound(rArray)
rArray(iVal) = UCase$(Prop.Name)
ReDim Preserve rArray(iVal + 1) As String
End If
Next
ReDim Preserve rArray(UBound(rArray) - 1) As String
EnumerateProperties = rArray
End Function
Public Function DoesPropertyExist(pObject As Object, ByVal _
PropertyName As String, pType As EPType) As Boolean
Dim Item As Variant
PropertyName = UCase$(PropertyName)
For Each Item In EnumerateProperties(pObject, pType)
If Item = PropertyName Then
DoesPropertyExist = True
Exit For
End If
Next
End Function
'-------------------------------------------------------------------------------
Then you can do something like this:
If DoesPropertyExist(Command1, "Caption", ReadableProperties) = True Then
Debug.Print "YES"
Else
Debug.Print "NO"
End If
The above example will check if the Readable property "Caption" exists for the control "Command1"... In this case it will return true...
If DoesPropertyExist(Command1, "Text", ReadableProperties) = True Then
Debug.Print "YES"
Else
Debug.Print "NO"
End If
In the above example we're checking if the "Command1" object contains the readable property "Text".... It does not, so it will return false.