JenniferMurphy
Well-known Member
- Joined
- Jul 23, 2011
- Messages
- 2,676
- Office Version
- 365
- Platform
- Windows
Does VBA support any kind of "keyword" parameter? By this, I mean parameters of the form keyword=value. Something like this:
I am working on a UDF that has half a dozen optional parameters with more to come. Most of them are omitted on most calls, taking the default value. As currently coded, this means that I have to remember the order, which is error prone and tedious. It also means that if I add a parameter, it has to go at the end, even if it will be the most frequently used parameter, or else I have to find and edit all previous calls.
If I could code them with keywords, I could enter them in any order and they would be self-documenting. I could also add parameters without having to change any existing calls.
I know I can do this with a Paramarray parameter, but then I have to parse the string. I was hoping that there might be an easier way.
Code:
=MyFun(A1, B2, Keyword4=C3, Keyword2=D4, ...)
I am working on a UDF that has half a dozen optional parameters with more to come. Most of them are omitted on most calls, taking the default value. As currently coded, this means that I have to remember the order, which is error prone and tedious. It also means that if I add a parameter, it has to go at the end, even if it will be the most frequently used parameter, or else I have to find and edit all previous calls.
If I could code them with keywords, I could enter them in any order and they would be self-documenting. I could also add parameters without having to change any existing calls.
I know I can do this with a Paramarray parameter, but then I have to parse the string. I was hoping that there might be an easier way.