Prevent multiple instances of Excel from starting

G

Guest

Is there a command line switch that will prevent Excel from opening multiple
instances of the application? I develop under excel and use an interface to a
thrid party middleware product. If the user opens multiple copies of Excel
then the middleware doesn't know which one to use and it's operations tend to
become unpredictable.

If there isn't a way to prevent multiple instances, how about a way to
detect it?

- Rm
 
G

Guest

I am not aware of a way to limit excel to one instance. I did have to deal
with a similar problem and initially we tried using GetObject to get 'other'
excel instance, but it did not always work. We ended up using Windows API
calls to get processes and then check for excel.exe by.

If there's an elegant way to reliably do this then I am interested as well.
 
P

Peter T

Hi John,

Thanga posted a C# routine here in message, see message #9 date view

http://tinyurl.com/9pbjv

I couldn't get it to work but probably due to my minimal knowledge of making
anything work in C# !

I have an "in-elegant" VBA method which is reliable enough for my purposes
though I wouldn't distribute as a production app, at least not as is. Maybe
a timing issue, occasionally fails first time though normally works on
second attempt. I briefly described it in message #6 of same thread.

Regards,
Peter T
pmbthornton gmail com
 
G

Guest

Thanks guys. I've explored some options that use the Windows API to check
the list of running processes. I don't really want to give my users the
capability to run scripts that simply terminate processes. That could lead to
some, well.... "problems".

I've noticed that a lot of objects in excel have an "Application" property.
There must be someway that I can compare "Applications" for each open
document and terminate all but one using the "Application.Quit". That seems a
little safer to me.

Any thoughts?


- Rm
 
P

Peter T

I suppose if you are administrating use of Excel in your organisation it
might be OK for you to close your colleagues' Excel instances in an orderly
way. But if that's not the case my "thought", as you asked, would be don't
even consider doing that!

In your OP you said "I develop under excel and use an interface to a
thrid party middleware product"

I don't follow the reason you need to close all but one instance, and the
criteria by which you would leave a given instance open.

If you know the FullName (not simply file name) of a particular file that's
of interest, if open it's normally possible to attach a ref to its instance
with GetObject(FullName).Parent.

Or maybe just start your own instance.

Regards,
Peter T
 
G

Guest

Perhaps I didn’t make it clear initially, the problem I have stems from
having multiple instances of the “Excel Task†running at the same time, not
multiple xl documents.

To see what I mean: Double click your excel icon. Minimise the window and
double click the icon again. Go to your task manager (sort by task name) and
you’ll see that there are two instances of Excel processing at the same time.
That’s want I want to prevent, not multiple windows on the start bar.

I don't have some malicious intent on making life difficult by randomly
closing peoples work for them. It would be much better to prevent a new excel
instance starting then have to close it after start – hence my original
question. The idea of closing tasks came up if it is not possible to prevent
multiple start-ups. In that sence my criteria for closing excel apps would be
"if one is running close the new one and maximise the old"

All Office products that run concurrently seem to “know†about each other.
They interact and react to each other. For example Outlook uses Word to
format emails and spellcheck. That’s one of the coolest things about
developing with Office tools. It’s this interaction between two instances of
Excel that seem to be causing the problem, confusing the 3rd party product.

Hopefully I'm making more sence. Thanks for you help.

- Rm
 
P

Peter T

I didn't have any confusion as regards multiple Excel instances vs multiple
xl files. I was trying to ascertain the process involved with your third
party app, and specifically the problem when multiple instances exist (I'm
not trying to imply there isn't a problem).

Does your app call Excel to reference a particular file (which may or may
not be open), or does some event (at application or workbook level) in a
given instance call your app. Or does your app simply require use of Excel
for it's own particular needs, eg calculation, generating files etc.
Depending on what does what to what there might be an easy solution.

FWIW changing Tools ? General > Ignore Other Applications
(xlApp.IgnoreRemoteRequests) will prevent multiple instances starting if
user loads a file from Explorer. But that won't stop all means of starting
multiple instances. Indeed should you prevent user from trying to.
All Office products that run concurrently seem to "know" about each other.

Yes and no!
They interact and react to each other. For example Outlook uses Word to
format emails and spellcheck.

Office apps share common components, but Outlook doesn't start an instance
of Word to use those tools, neither does a given app automatically know what
others are running, and especially how many

Regards,
Peter T
 
G

Guest

The 3rd party product is an OLAP-DBMS. We link it to Excel via an add-in that
was provided by the 3rd party which contains a number of worksheet formula
specifying data-slices. I also tend to use it as a COM object in VBA because
I find the formula interface a bit cumbersome.

The addin starts a background task that controls all the data access
calculations. So presumably it's using the DBMS as COM object too. Excel is
only used to display and input data, few data calulations just UI. The task
is more or less an executable file, an application that can be started
without excel.

A lot of the addins functions are based on worksheet ranges for input and
output of the OLAP slices. For some reason these formula don't like to work
when multiple instances of Excel are open together. It's almost as if there's
a programming error where someone hasn't properly referenced the a range
properly.

I don't have access to get in an look at what's going-on in the addin.
They're very protective of their little chunk of code. I'm not sure why, the
whole product is a little bit unstable and has a number of, well I'll call
them quirks to be polite. I seem to find myself constantly looking for work
arounds like this one.



- Rm
 
P

Peter T

If your third party stand alone app is doing it's own thing with it's own
instance of Excel, I don't think it would matter how many instances exist.

A guess, and a wild guess, perhaps the problem is the opposite of what you
think, namely not enough instances, ie user inadvertently using your app's
instance. Your app starts a new (invisible) instance for it's own purposes,
if then user opens an xls via explorer this may open up in your app's
instance and also make it visible. But later user closes that instance your
app is lost!.

You can demonstrate this for yourself -

Uncheck "Ignore other applications" in Tools / General.
Close all instances of Excel.
In Word, insert a new module (Alt-Fll, Alt-i, m)

Dim oXL As Object
Dim oWB As Object
Dim bRequests As Boolean

Sub StartXL()

Set oXL = CreateObject("Excel.Application")
Set oWB = oXL.Workbooks.Add
bRequests = oXL.IgnoreRemoteRequests

'oXL.IgnoreRemoteRequests = True

oWB.Worksheets(1).Range("A1") = "Started by Word"
MsgBox oWB.Name
' oXL.Visible = True

End Sub

Sub CloseXL()
Dim wbCount As Long
On Error Resume Next
oWB.Close False
Set oWB = Nothing
If Err.Number Then
MsgBox "oWB does not exist"
Err.Clear
End If
wbCount = oXL.Workbooks.Count
If wbCount Then
MsgBox "Someone's got a WB open in my XL !"
oXL.Visible = True
Exit Sub
End If

oXL.IgnoreRemoteRequests = bRequests
oXL.Quit

If Err.Number Then
MsgBox "oXL does not exist"
Err.Clear
End If
Set oXL = Nothing

End Sub

Start an invisible XL with StartXL

Now double click an xls file in Explorer to open

It's opened in Word's instance of xl - right?. Close the file you just
opened

Run CloseXL

Repeat but his time also close XL manually after loading some file. Run
CloseXL again.

Repeat again, don't manually close the xls you just open but close via Word

And yet again but this time un-comment the line
'oXL.IgnoreRemoteRequests = True

As I say, all this is entirely a guess as to your problem, and doesn't quite
fit what you say about your app only using Excel to display and input data.

Regards,
Peter T
 

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