I'm trying to use ParamArray to pass different kinds of parameters to the same function to mimic Function Overloading.
- One single
String
- One
Workbook
object, oneString
as well as anInteger
So user may pass different arguments to the same function:
Function func(ParamArray params() As Variant)
blah = func("This is a string")
blah = func(wbSource, "SheetName", iRow)
Is there a way to validate the types of arguments? I need to make sure that params() contains the right types of arguments (one workbook
, one string
and one integer
).
For sure I can hard code with a bunch of If-Else
, but what if in the future there are more arguments? I'm thinking about using TypeName()
to dump the types to a String
array and then do the comparison. But this still seems to be cumbersome. Is there a better way to achieve this?
BTW I don't think Optional
is a good idea because who knows how many arguments there will be?