Denis Pitcher

When launching excel via interop, I've noted that the addins don't appear to load.

Dim xlsApp As Microsoft.Office.Interop.Excel.Application

xlsApp = New Microsoft.Office.Interop.Excel.Application

xlsApp.Visible = True

Does anyone have any idea why and how to solve it Otherwise, I need to figure out how to load excel via System.Diagnositics.Process.Start() where I can pass it the location of the excel exec, which I am uncertain how to determine




Re: Visual Studio Tools for Office add-in doesn't load when launching using new excel.application

Dennis Wallentin

Denis,

This forum explicit target VSTO and automation of Excel via VB.NET is beyond its boundaries. However, below You will find additional information.

The behavior You see is per design and depending on the task You may choose a different approach. The following example shows how we can load XLAs and COM add-ins when automating Excel:

Imports Excel = Microsoft.Office.Interop.Excel

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim xlApp As Excel.Application = New Excel.Application

Dim Counter As Integer

Dim xlaName As String = "SUMIF.XLAM"

With xlApp

'Example for xla.

For Counter = 1 To .Application.AddIns.Count

If .Application.AddIns.Item(Counter).Name = xlaName Then

.Application.AddIns.Item(Counter).Installed = True

End If

Next

'Example for COM add-ins.

.Application.COMAddIns.Item("CaseXL.Connect").Connect = True

.Visible = True

.UserControl = True

End With

xlApp = Nothing

End Sub

End Class






Re: Visual Studio Tools for Office add-in doesn't load when launching using new excel.application

Denis BDA

Thanks Dennis,

Yes, I likely should have moved this to another forum as although I am working with a VSTO project, it fits best with excel automation. The reason why I chose to post it here was because I was loading a project with an application addin via automation and was wondering if because it was VSTO if it could be causing the problem uniquely because it was a VSTO addin.

I made a few changes and found that processes.start caused the add-ins to load properly where loading it via interop did not. I'm not sure if this is VSTO specific or generic to any means you try to load add-ins so I'm including my notes here.

For a bit more context. This initalization of excel is happening within a separate application that I am using to kill the current excel process and launch a new one so that I can reload my updated addin after having copied the latest files from a network share. (a hacked attempt at fixing click-once)

I can't figure out why the add-in doesn't load in this scenario but it seems the simple work around is to use:

Determine the startup path of the original instance using

Application.Path + "\excel.exe"

System.Diagnostics.Processes.Start(_startupPath)






Re: Visual Studio Tools for Office add-in doesn't load when launching using new excel.application

Steve Hansen

Hi Denis,

As Dennis pointed out, this behavior is by design in Excel. It is not an interop or VSTO issue. Whenever you create an instance of Excel as an automation object, add-ins will not load unless you explicitly load them. One of the reasons behind this design decision is that if you are using Excel as an automation object, you probably might have more interest in the Excel application initializing quicker. By not loading add-ins automatically, it gives the programmer much more control over what happens in this scenario.

While the following link is VBA specific, it provides some relevant details:

http://support.microsoft.com/kb/213489

Regards,

Steve Hansen






Re: Visual Studio Tools for Office add-in doesn't load when launching using new excel.application

Dennis Wallentin

Denis,

COM add-ins created with VSTO do behave as the other COM add-ins. The Processes.Start is similar to start Excel manually and therefore the add-ins are loaded.






Re: Visual Studio Tools for Office add-in doesn't load when launching using new excel.application

Denis BDA

Good to know, thanks guys, appreciate the feedback