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?
There are two ways for the Excel-DNA based RTD server to be used from Excel:
XlCall.RTD(...)
or,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...