ExcelDna: Function returns a #VALUE! when it should return #NAME?

Hello guys! In Excel: =HelloWorld(TRUF) Returns "Hello World!" even if parameter TRUF returns #NAME? in Function Argument Window (Ctrl + A). =HelloWorld(TRUF) should return #NAME?.

C# Code:

using ExcelDna.Integration;

public static class MyFunctions
{
    [ExcelFunction(Description = "Hello world")]
    public static string HelloWorld(
[ExcelArgument("True or False?")] bool foo)
    {
        return "Hello World!";
    }
}

Thanks

About this issue

  • Original URL
  • State: open
  • Created 7 years ago
  • Comments: 18 (6 by maintainers)

Most upvoted comments

Your object will be of type ExcelError which is an enum. This function describes the parameter:

				// This function returns a string that describes the argument value.
				// For arguments defined as 'object' type, this shows all the possible types that may be received.
				// Also try this function after changing the 
				// [ExcelArgument(AllowReference=true)] attribute.
				// In that case we allow references to be passed (registered as type R). 
				// By default the function will be registered not
				// to receive references but that actual target value - AllowReference=false (type P).
				[ExcelFunction(Description="Describes the value passed to the function.", IsMacroType=true)]
				public static string Describe([ExcelArgument(AllowReference=false)]object arg)
				{
						if (arg is double)
							return "Double: " + (double)arg;
						else if (arg is string)
							return "String: " + (string)arg;
						else if (arg is bool)
							return "Boolean: " + (bool)arg;
						else if (arg is ExcelError)
							return "ExcelError: " + arg.ToString();
						else if (arg is object[,])
							// The object array returned here may contain a mixture of different types,
							// reflecting the different cell contents.
							return string.Format("Array[{0},{1}]", ((object[,])arg).GetLength(0), ((object[,])arg).GetLength(1));
						else if (arg is ExcelMissing)
							return "<<Missing>>"; // Would have been System.Reflection.Missing in previous versions of ExcelDna
						else if (arg is ExcelEmpty)
							return "<<Empty>>"; // Would have been null
						else if (arg is ExcelReference)
              // Calling xlfRefText here requires IsMacroType=true for this function.
							return "Reference: " + XlCall.Excel(XlCall.xlfReftext, arg, true);
						else
							return "!? Unheard Of ?!";
				}

Thanks for this @govert