Optional worksheet parameters and default values

| 0 Comments | 0 TrackBacks
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.

No TrackBacks

TrackBack URL: http://www.jetxll.net/cgi-bin/mt/mt-tb.cgi/11

Leave a comment

Recent Entries

Optional worksheet parameters and default values
Your custom worksheet functions can take optional parameters. The users of your worksheet can then decide whether to supply them…
Integrating your addin with Excel - the function wizard
Whilst it's very easy to create a worksheet function using C# with JetXLL simply by adding the [WorksheetFunction] attribute to…
Debugging a JetXLL addin
As you saw in the previous article, it's easy to build a custom worksheet function for Excel with JetXLL. Of…