Hi Anthony,
> VBA testing for .Object is Nothing seems to find the real one OK.
No, no, no. What if another add-in has set the .Object?
Testing the first part of the description is better, because you can
control the name of your add-in, and it is likely to be the only add-
in loaded with that name. I agree it's a bit fragile, but it's my best
suggestion for now. Long term you should just move everything into
managed code ;-)
> I think this is a result of not having a ProgId. Is there any way to
> set this?
No way to set it for the ExcelComAddins in the current versions. I
agree, the auto-generated ProgId is not so useful here. I'l consider
whether this should change (similar to RTD servers). I have to re-look
at the ribbon ProgId stuff also in future. The reason for the auto-
generated ProgId is to make sure different instances of the add-in
don't trash each other (since I'm doing registration at runtime).
The alternative is then to not go the ExcelComAddIn route, but the
real ComServer option, where you can set the ProgId and control what
is instantiated from VBA better. But this has other complications....
So for now I'd first suggest checking BOTH
1. the start of the Description string (which will match your add-in's
name), and
2. that the .Object != null. Excel-DNA does not set it for a Ribbbon
or Rtd helper, so you control whether it is set for ComAddIns with
your add-in's name.
> One problem I have is that I actually end up with multiple instances
> of the add in installed. They all end up in
> HKEY_CURRENT_USER\Software\Microsoft\Office\Excel\Addins
> with random names like AddIn.92bf9e5a30e747b2b35b4f15bb54bd5d
You might get some left-overs here if you are debugging and the add-in
crashes or you stop the debugger. But normal operation should not
leave extra entries here. (Please report if it does.)
> The next problem is how to actually open the add in. It's path is not
> in the registry entries.
Which add-in? The Excel-DNA add-in?
This you can either File->Open, or add as an Excel add-in under (Alt
+t, i), or add into the registry with an installer.
The COM add-in you implement with ExcelComAddIn will be loaded by the
Excel-DNA add-in automatically.
> File > Open does seem to work, but
> with macro security warnings, each time.
Options are: change macro security settings, sign your add-in, or add
as a regular add-in in the add-ins dialog.
> I do not want to resort to a SendKeys Hack!
Please don't.
> I suspect this is all to do with no ProgID.
No. You might be confusing different 'add-ins'.
> Another issue is that you use .Net 4.0 dynamic magic.
> I could not see
> how to run this with 3.5, which is much more available.
Sorry - that was just to make my little test easier.
You can do the same in .NET 2.0 by
1. using reflection (InvokeMember), or
2. adding a reference to the Excel Interop assembly (or the NetOffice
library) and cast the AddInInst to a Microsoft.Office.Core.ComAddIn
type. You seem to have done this in your example.
Write if you need help with either of these options.
> That AddInInst parameter has a weird System.__COMObject type, which
> Microsoft.VisualBasic.Information.TypeName(AddInInst) reports to be
> "COMAddIn", but I do not believe it. COM must hook deeply into
> the .Net type system, pretending that the dynamic COM proxy object is
> the real one. Anyway help here would be appreciated.
COM / .NET interop is an enormous topic. Indeed .NET deeply integrates
with COM, and does a really good job too, but still lots of tricky
issues.
> Thanks for your great support.
It's a pleasure - thanks for your interest in the Excel-DNA library!
Cheers,
Govert