Adding COM functions at runtime

91 views
Skip to first unread message

Sean Tomlinson

unread,
Oct 24, 2022, 6:44:38 AM10/24/22
to Excel-DNA
I am building an excel add in that allows users to run a function that creates further functions at runtime.

So far, I have been able to register new excel functions at runtime using:
ExcelAsyncUtil.QueueAsMacro(() => {
    ExcelIntegration.RegisterDelegates(delegates, methodAttributes, argumentAttributesCollection);
    ExcelDna.IntelliSense.IntelliSenseServer.Refresh();
});

The add in also supports VBA with the use of a COM server. E.g:
[ComVisible(true)]
[ClassInterface(ClassInterfaceType.AutoDispatch)]
[ProgId("Test123")]
public partial class VBAFunctions : IVBAFunction
{
    public object MyFunc() => "Hello World!";
}

Then from VBA:
Dim lib As Object: Set lib = CreateObject(" Test123")
Dim arr As Variant
arr = lib.MyFunc()

I am wondering if it is possible to add functions at runtime to be accessed via VBA in a similar fashion to adding excel functions as above? Thanks!

Danyaal Khan

unread,
Oct 28, 2022, 5:19:22 AM10/28/22
to Excel-DNA
Hi all,

I'm looking to implement similar functionality to add functions for Excel VBA during runtime but I haven't encountered a way to implement it, so a solution to this would be very useful!
Reply all
Reply to author
Forward
0 new messages