mvorisek
mvorisek

Reputation: 3418

Excel DNA and RTD server COM visibility

In every Excel DNA RTD sample the RTD server impl. is marked as COM visible. Example: https://github.com/Excel-DNA/Samples/blob/master/RtdClocks/RtdClock-ExcelRtdServer/RtdClockServer.cs

Based on my testing when Excel DNA addin is added to Excel, the COM visibility is NOT needed.

What is the reason to make the RTD impl. COM visible?

Upvotes: 2

Views: 1034

Answers (1)

Govert
Govert

Reputation: 16907

There are two ways for the Excel-DNA based RTD server to be used from Excel:

  • with no registration and a wrapper UDF that internally calls XlCall.RTD(...) or,
  • by registering the types (with a call to ExcelDna.ComInterop.ComServer.DllRegisterServer()) and then calling the =RTD(...) function directly.

For the normal first case, you're right the ComVisible is not required for the RTD server - Excel-DNA internally does the hook-up and exposes the class without registration. For the second case, ComVisible is required (either explicitly or by having no ComVisible directive on the type or assembly - since the default for ComVisible is 'true') for the type to be registered as a COM export.

This story is complicated a bit if you try to use a wrapper function, but have a stable ProgId registered with Excel so that 'old values' can be used when a saved sheet is re-opened. In this case you need to have the COM registration and change your wrapper to call XlCall.Excel(XlCall.xlfRtd, ...).

So you're right that for most of the Excel-DNA samples it's not actually required.

It all got a bit confusing over the years...

Upvotes: 5

Related Questions