I'm 99% sure that the answer is "no", but I'm wondering if someone who is 100% sure can say so.
Consider a VBA UDF:
Public Function f(x)
End Function
When you call this from the worksheet, 'x' will be a number, string, boolean, error, array, or object of type 'Range'. Can it ever be, say, an instance of 'Chart', 'ListObject', or any other Excel-VBA object model class?
(The question arose from me moving to Excel 2007 and playing with Tables, and wondering if I could write UDFs that accept them as parameters instead of Range
. The answer to that seems to be no, but then I realized I didn't know for sure in general.)
Your suspicions are correct - you can only pass in limited object types. For example, if I have table on the active worksheet and wanted to know it's column count, I could create a UDF called
TableColumnCount
and pass in the table name into a function like:and then call it on sheet with the name of my able as a string, like
=TableColumnCount("Table1")
.Or as a range object like:
And then call it like:
=TableColumnCount(Table1)