Excel Automation Addin Problem  
Author Message
Luis Simões





PostPosted: Visual C# General, Excel Automation Addin Problem Top

Hi,

I created a class with several User defined Functions that i use in excel, but now i needed to pass several values to the functions like this: =Function1("val1"; "val2", ...) and so on... the number of arguments are unknown and this is the big problem...

How can i get an unknown number of parameters from the excel formula

I'm trying to get into this for about 5 months now...
I have tried the paramarray and params methods without success, i think its because in vba or normal vb the paramarray/params works by reference and in .net it would only work by value.

I need one solution for this in VB.NET or C#.

Best Regards,
Luis Simoes




Visual C#3  
 
 
Bogdan Crivat





PostPosted: Visual C# General, Excel Automation Addin Problem Top

This seems to work:

public object MYUDF(

[System.Runtime.InteropServices.DefaultParameterValue(null)] object value1,

[System.Runtime.InteropServices.DefaultParameterValue(null)]object name1,

[System.Runtime.InteropServices.DefaultParameterValue(null)]object value2

... )

Hope this helps



 
 
Luis Simoes





PostPosted: Visual C# General, Excel Automation Addin Problem Top

Hi Bogdan,

Thank you for your post,

Anyway is there any way to receive an array of parameters Or do i have to define a specific number of input parameters

Best Regards,



 
 
Bogdan Crivat





PostPosted: Visual C# General, Excel Automation Addin Problem Top

I am not sure whether it is possible to get a parameter array. All my attempts to use array of parameters in a C# UDF failed. It may be possible with some COM Interop code (using a SAFEARRAY which can be wrapped in a VARIANT), but I did not try this yet.

Eventually, I added a large number of nullable parameters and, internally, I read them one by one until I encounter the first null.