Problem with getting ADX host Excel Instance and current cell address

Add-in Express™ Support Service
That's what is more important than anything else

Problem with getting ADX host Excel Instance and current cell address
Problem with getting ADX host Excel Instance and current cell address 
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,
Posted 09 Apr, 2015 09:08:28 Top
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
Posted 10 Apr, 2015 02:46:22 Top