ExcelDNA AddIn as an externally visible COM server

Aug 1, 2012 at 2:54 PM

Hi,

My ExcelDNA AddIn is using a client socket to connect to a server. I would like to enable an external program to tell the plugin to initiate the connection.

There are multiple discussions on this forum on how to make a COM server that Excel's own VBA can instantiate. But what I am looking for is for a separate process, outside of Excel, to call a function on the loaded plugin.

Does the plugin need to be its own externally visible COM server? Or is there a way for an external program calling Excel itself through COM to get a reference to my plugin and call a method on it?

My knowledge of COM is very limited and I would appreciate any help pointing me in the right direction.

Thanks!

Coordinator
Aug 1, 2012 at 6:37 PM

Hi,

You won't (easily) be able to run the Excel-DNA add-in outside of Excel.

You can easily automate Excel from an outside app (or PowerShell) using COM. After activating Excel and getting the Application object, you can load the add-in with Application.RegisterXLL(thePath), and then run a macro or function in the add-in using Application.Run("MyMacro", "Param1").

-Govert

Aug 2, 2012 at 6:12 PM

Thanks!

I really like your idea of having a macro to "turn on" my add-in, instead of exposing some new COM interface from the add-in to do this.

One difficulty I am having is that the macro must be a static function, while the add-in gets instantiated. How do I get a reference to current instance of the add-in from within the static function?

I also wanted to try out the latest code from the code repository (v. 75950), so I plugged-in that latest ExcelDna.Integration.dll and ExcelDna.xll and while the plugin shows up as loaded in Excel's list, it does not run AutoOpen() and AutoClose(). Reverting back to the versions of those files from ExcelDna-0.29.zip makes the plugin work again. Any idea why  I am seeing this behavior?

One again, thanks a lot for your help.

Coordinator
Aug 2, 2012 at 10:03 PM

Hi,

Your IExcelAddIn.AutoOpen can write to some static variable, which you could then access from the static functions or macros.

The latest version should work fine. Make sure that the renamed copy of the ExcelDna.xll and the ExcelDna.Integration.dll that you use really match (your .xll in the output directory might still be the old one.) Also, you don't need the ExcelDna.Integration.dll in the output directory - deleting it sometimes helps.

-Govert

Aug 3, 2012 at 5:20 PM

Thanks a lot.  Everything is working now.