Your custom worksheet functions can take optional parameters. The users of your worksheet can then decide whether to supply them or leave them blank. Optional parameters can be indicated in one of two ways, as with parameter help strings that were explained in a previous article.
Either using the [Optional] attribute, as shown above. Or by using the IsOptional parameter of the [ParameterDetails] attribute as shown below.
If an optional parameter is not supplied to the worksheet function then you get passed a zero value for all numeric types and an empty string for string types. Sometimes you may wish to provide your own default value for a missing optional parameter. In that case you can use the [DefaultValue] attribute or the DefaultValue parameter to the [ParameterDetails] attribute. See below:
Default values can also be supplied for array parameters, see below:
Finally, you may prefer to indicate to your users which parameters are optional and which are not, you can do this by setting the OptionalParameterEmbelishment parameter of the [AddinClass] attribute to UseSquareBrackets which causes all optional parameters to be displayed in the function wizard within square brackets.
You can download the source code for this example code from here. You will need a copy of JetXLL to be able to build and run the code.
Optional worksheet parameters and default values
No TrackBacks
TrackBack URL: http://www.jetxll.net/cgi-bin/mt/mt-tb.cgi/11
Leave a comment