Wrapping RTD function in Automation add-in

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

Wrapping RTD function in Automation add-in
Wrapping RTD function in Automation add-in 
sgonzales




Posts: 15
Joined: 2010-03-22
I've followed the example of wrapping an RTD in an Excel Automation add-in (http://www.add-in-express.com/docs/net-excel-udf-tips.php#advanced-rtd) but it does work.

I get the error : 'Excel.WorksheetFunction' does not contain a definition for 'RTD' and no extension method 'RTD' accepting a first argument of type 'Excel.WorksheetFunction' could be found (are you missing a using directive or an assembly reference?)

Here's the method in C#:

public object CurrentPrice(string topic)
{
Excel.Application ExcelApp = (Excel.Application)Marshal.GetActiveObject("Excel.Application");
Excel.WorksheetFunction wsFunction = ExcelApp.WorksheetFunction;
object result = null;
try
{
result = wsFunction.RTD("Stock.Quote", "", topic, "Last");
}
catch
{
}
finally
{
Marshal.ReleaseComObject(wsFunction);
}
return result;
}
Posted 11 May, 2010 15:13:34 Top
Andrei Smolin


Add-in Express team


Posts: 14094
Joined: 2006-05-11
Hi Jeffrey,

This is because you use version-neutral interops; in case of Excel, it is an interop for Excel 2000. And RTD was introduced in Excel 2002. You have two ways:
- switch to using interops for Excel 2002 or higher
- use late binding to access that method

Please pay attention to Supporting several Office versions in an add-in. Interop assemblies and late binding..

Regards from Belarus (GMT+2),

Andrei Smolin
Add-in Express Team Leader
Posted 12 May, 2010 09:59:09 Top