How to check if an object has a certain property?

  • Thread starter Thread starter J
  • Start date Start date
J

J

If I have a procedure that takes as input an object, how do I
programmatically check to see if that object has a height property?

Function CheckForHeightProperty(InputObject as Object)

?? How do I check to see what properties this object has? Is there any way
to enmurate them programmatically??

End Function
 
Hi

I'd do it the brutal way; ask for it and check for errors:

Function HasHeight(InputObject As Object) As Boolean
Dim D As Double
On Error Resume Next
D = InputObject.Height
If Err.Number = 0 Then HasHeight = True
End Function

Sub test()
MsgBox HasHeight(ActiveSheet.Rows(4))
MsgBox HasHeight(UserForm1)
MsgBox HasHeight(Application.AnswerWizard)
End Sub

HTH. Best wishes Harald
 
Back
Top