Pete_J

Hi,

We have created an automation add-in for adding hotkeys to Excel 2007.

On two developers machines/profiles, the automation add-in is invoked on Excel start up, and on the third, the add-in starts up as expected - on demand when our function is called [i.e. when a shortcut/hotkey combination is pressed].

So....

1) What could be causing the Automation add-in to load on Excel startup on the other two machines (on both, the add-in appears in the "Add-in" and not the "Com Add-ins" which would, I believe had been one possible cause of this). As a test, we have also commented out the "OnKey" calls which setup the listener for the Excel functions (and thus eliminated any chance of this being an genuine inadvertent on-demand call.

2) Is there any way of tracing the events prior to the construction of the automation class This may give a clue to what is causing this to be created on Excel load. Looking at the call stack in Visual Studio didn't help.

The issue we have is that in the constructor, we are catching a reference to the application and on Excel start up, this is null. We could move this code, but that would be a hack and it would be better to understand and resolve the source of the issue.

I understand that the load behaviour for the automation add-in should always be on-demand and for a com add-in is determined by the setting of the load behaviour setting in the registry. Is seems possible that a setting is at play here as we are all running from the same code base...

Many thanks.

BTW, Here is a sample of the method header (to give more flavour as to what we are up to)

[ClassInterface(ClassInterfaceType.AutoDual)]

[ProgId("OurAddin")]

[ComVisible(true)]

[Guid("....")]

public class HotKeys

{

private ExcelApp.Application application;



Re: Visual Studio Tools for Office Why does an Excel Automation add-in load on Excel start up (and not on-demand as expected)

Mike Walker

Are you using a VSTO Solution this forum is based on this technology that wrappers the IDTExtensibility interface. Can you give some more information, COM Addins (IDTExtenisibility2) Interface or Addin Based VSTO Solutions with VSTO 2005 SE will load at application load/startup if all settings are correct. I am keen to know more information.

Regards






Re: Visual Studio Tools for Office Why does an Excel Automation add-in load on Excel start up (and not on-demand as expected)

Pete_J

Thanks for the response Mike,

The plot is a little thicker...the hotkeys Automation Add-in is "spawned" off our main Excel Addin and is contained as a class (with the header code above) in our main add-in codebase.

For installation, we have a VB script which registers this in the registry HKCU\Software\Microsoft\Office\12.0\Excel\Options\OPENx, sHotKeys and it can then be seen as a separate add-in in the Excel add-in list under options.

From the literature,

1) If the add-in is only in the add-ins dialog box - Add-in is loaded on demand.

2) If the add-in is listed only in the COM add-ins dialog box - the load behavious is determined from the registry settings.

3) If the add-in is listed in both the add-ins and COM add-ins then two instances are loaded one of each of the above.

On one machine, the object is being instantiated on demand (i.e. the first hotkey press), on the other two machines, it is being instantiated on startup of the add-in. The settings re: the above are all the same (i.e. case '1)')

Code-wise...

There is a function is ThisAddin.cs (the main add-in) which iterates through the config file which contains shortcut key <--> function combinations and uses "this.application.OnKey" to set up listeners.

and an automation class "HotKeys", which contains a constructor and a member function for each of the hotkey operations (matching those added by the Onkey above).

In the constructor for the Hotkeys, we are catching a reference to the application. If the add-in is called on start up, then this is not initialised and we get problems later with a null application pointer, as I elude to above, there are alternative approaches we can take to this, however it would be good to underastand why the load behaviour is different.





Re: Visual Studio Tools for Office Why does an Excel Automation add-in load on Excel start up (and not on-demand as expected)

Dennis Wallentin

Hi Pete,

Why does an Excel Automation add-in load on Excel start up (and not on-demand as expected)

Please see if the following article kan help You out: Excel COM add-ins and Automation add-ins






Re: Visual Studio Tools for Office Why does an Excel Automation add-in load on Excel start up (and not on-demand as expected)

Pete_J

Thanks Dennis,

None the wiser on the startup differences across the machines, but what I have done is....

I have implemented the IDTExtensibility2 interface and picked up the application instance from that, this is more elegant and works the same on all machines. Hopefully there is no down-side to this that I am not aware of.

public void OnConnection(object Application, ext_ConnectMode ConnectMode, object AddInInst, ref Array custom)

{

application = (ExcelApp.Application)Application;

}