excel interop: identifying when excel has "initialized"

G

Guest

This is a question about Excel interop. Any insight would be appreciated.

Question:

Is there any way (ie. event, property, hack, etc) to know when Excel has
initialized? I know this is probably not well-defined, but I would define it
as "all addins for the particular Excel process have initialized" since that
is most useful to my situation.

I have looked at a number of the interop capabilities (properties, events,
etc), nothing i have tried works though.

Background:

We are writing a program in .Net 1.1 using C# that targets the Excel 2000
Interop assemblies, but is being tested with Excel 2003 application which has
some 3rd party addins installed.

We have observed:

1) when "new Excel.ApplicationClass()" is used to start a new Excel process,
the addins do not properly initialize.

2) when starting a new Excel process using Process.Start(), the addins
initialize properly if I wait long enough (eg. sleep for 10 seconds to give
them time)

2.1) if I do not wait long enough, race-condition results occur, and the
addins do not initialize. other side effects (multiple excel processes, error
dialogs) also occur depending on situation, number of addins, etc.

2.2) "waiting long enough" is not well-defined since it is unknown the addin
configuration of a given client. also addins can raise dialogs on load which
require user feedback to complete.

Once again, any insight would be appreciated. Thanks.
 
N

NickHK

Peter,
I can't answer your question for .Net, but from VB6:
Dim XLApp as Excel.Application
Set XLApp=New Excel.Application
XLApp.Workbooks.Add

The last line cannot execute until the Excel instance is up and running.

Excel 2003 (or maybe 2002) has an Application.Ready property that you can
may be check. It is supposed to indicate if Excel can respond. However, if
it cannot respond, I don't know how it is supposed to return the value of
this property. It apparently always returns True, which makes sense as it
would be illogical to return False.

Dim XLApp As Excel.Application

Private Sub Form_Load()
Dim i As Long
Dim InstalledCount As Long

Set XLApp = New Excel.Application

With XLApp
For i = 1 To .AddIns.Count
If .AddIns(i).Installed = True Then
InstalledCount = InstalledCount + 1
End If
Next
MsgBox "There are " & InstalledCount & " addins installed"
.Visible = True
'.Quit
End With

End Sub

So I would assume your problems are thread related and/or the way .Net
instantiates objects compared to VB.

NickHK
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top