Passing either a Named Range Or a 3D Object Array to an Excel-DNA UDF

20 views
Skip to first unread message

Scott Gall

unread,
Sep 28, 2021, 3:12:06 PMSep 28
to Excel-DNA
Good Day,

I am trying to write an Excel UDF which will take a number of parameters. I would like some of these parameters to be three dimensional (3D). 
I have tried several things so far:

Attempt 1:
Snippet[ExcelFunction(Name = "TestFunction", Category = CATEGORY)]         public static object[,] TestFunction(         [ExcelArgument(Name = "Parameter 1 (2D Range)", Description = "Descrip")] object[,] param1,         [ExcelArgument(Name = "Parameter 2 (2D Range)", Description = "Descrip")] object[,] param2,         [ExcelArgument(Name = "Parameter 3 (3D Range)", Description = "Descrip")] object[,,] param3)         {             #region PrepResult             ExcelReference excelRef = (ExcelReference)XlCall.Excel(XlCall.xlfCaller);             int numRows = excelRef.RowLast - excelRef.RowFirst + 1;             int numColumns = excelRef.ColumnLast - excelRef.ColumnFirst + 1;                          object[,] result = new object[numRows, numColumns];                          #endregion             return result;         }

Result 1 - "Initialization [Error] Method not registered - unsupported signature, abstract or generic..."

Attempt 2:

Snippet[ExcelFunction(Name = "TestFunction", Category = CATEGORY)]        public static object[,] TestFunction(        [ExcelArgument(Name = "Parameter 1 (2D Range)", Description = "Descrip")] object[,] param1,        [ExcelArgument(Name = "Parameter 2 (2D Range)", Description = "Descrip")] object[,] param2,        [ExcelArgument(Name = "Parameters", Description = "Description")] params object[] args)        {            #region PrepResult            ExcelReference excelRef = (ExcelReference)XlCall.Excel(XlCall.xlfCaller);            int numRows = excelRef.RowLast - excelRef.RowFirst + 1;            int numColumns = excelRef.ColumnLast - excelRef.ColumnFirst + 1;                        object[,] result = new object[numRows, numColumns];                                    #endregion            return result;        }

where I would use a formula like this: 
=TestFunction(I1:J2,I4:J5,S3:S7,T3:T7)
or 
=TestFunction(I1:J2,I4:J5,S3:S7,T3:T7) (with the named range test = a 3D Range like "S3:S7,T3,T7")
 
Result 2:  Either #Value Error where it never debugged or args = ExcelDna.Integration.ExcelError.ExcelErrorValue


Is there any way I can get an object[,,] from a parameter with Excel-DNA? Hopefully it's something small I'm missing.

Thank you in advance for any help provided.
Scott
Reply all
Reply to author
Forward
0 new messages