LAKULESH PATEL
Guest
|
Hi,
We have created a COM ADX project for excel with AddinModule.cs and ExcelAddinModule.cs added.
We added a UDF in ExcelAddinModule.cs similar to below:
public object MyUDF(string param1, string metricName, [Optional] object param3, [Optional] object param4, [Optional] object param5, [Optional] object param6, [Optional] object param7, [Optional] object param8, [Optional] object param9, [Optional] object param10, [Optional] object param11)
{
return param1;
}
We want to get the current Excel instance and current cell in which formula is entered in the above UDF. We ttried to get Excel instance in the above UDF using AddinModule.CurrentInstance.ExcelApp, but we are getting exception saying AddinModule.CurrentInstance is null. Could you please let us know how to achieve this ?
Thanks, |
|
Andrei Smolin
Add-in Express team
Posts: 18791
Joined: 2006-05-11
|
Hello Lakulesh,
Here's what we suggest in https://www.add-in-express.com/docs/net-excel-udf-tips.php#determining-cell:
In your Excel Automation add-in, you cast the ADXExcelAddinModule.HostApplication property to Excel.Application and get ExcelApp.Caller in VB or call ExcelApp.get_Caller(Type.Missing) in C#. That method typically returns an Excel.Range containing the cell(s) the UDF is called from (see the Excel VBA Help Reference on Application.Caller).
Hope this helps.
Andrei Smolin
Add-in Express Team Leader |
|