0

How to show "You've entered too few arguments for this function" message in custom functions created using Excel DNA?

Beryl Wilson
  • 125
  • 8

1 Answers1

0

With Excel's C API (which Excel-DNA uses to integrate with Excel) there' no way to indicate that a parameter is mandatory, so you won't get the message from Excel. However, you can deal with the situation inside your function. If your parameter is set to be of type 'object', any missing values will be passed as ExcelMissing.Value. You can detect this and respond with a MessageBox, or by returning some information string as the result.

In C# you might try something like:

public static object MyFunction(object arg1)
{
    if (arg1 is ExcelMissing) 
    {
        MessageBox.Show("You've entered too few arguments for this function");
        return ExcelError.ExcelErrorValue;
    }

    // Now use arg1...
}
Govert
  • 16,387
  • 4
  • 60
  • 70