The official response from Microsoft technical support on this question is
that you cannot implement a UDF in a VSTO application. It is neccesary to
create a second add-in which uses a hidden worksheet or remoting for
communication.
- Show quoted text -
It looks to me like a shimmed Automation add-in is what you want.
That will do UDFs, and can be automatically loaded by C# code in your
VSTO add-in along these lines:
private static void SetUpAutomationAddIn(Excel.Application
excelApp, string automationAddInProgId)
{
// Can't enumerate this Office collection with foreach.
See
//
http://support.microsoft.com/default.aspx?scid=kb;en-us;328347
for (int i = 1; i <= excelApp.AddIns.Count; i++)
{
if (excelApp.AddIns
.progID ==
automationAddInProgId)
{
if (excelApp.AddIns.Installed == false)
{
excelApp.AddIns.Installed = true;
}
// The Automation add-in is set up.
return;
}
}
// Add a workbook if there isn't already one there. Need
to do this
// to ensure that the AddIn manager is available before we
call AddIns.Add.
// See Microsoft Knowledge Base Article - 280290
if (excelApp.Workbooks.Count == 0)
{
excelApp.Workbooks.Add(Missing.Value);
}
AddIn addedAddIn =
excelApp.AddIns.Add(automationAddInProgId, true);
addedAddIn.Installed = true;
}