ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to check if an object has a certain property? (https://www.excelbanter.com/excel-programming/318345-how-check-if-object-has-certain-property.html)

J

How to check if an object has a certain property?
 
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



Harald Staff

How to check if an object has a certain property?
 
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


"J" skrev i melding ...
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






All times are GMT +1. The time now is 01:24 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com