check if there is a second instance of Excel running

smiler44

Registered User.
Local time
Today, 10:33
Joined
Jul 15, 2008
Messages
671
I want to check to see if there are any other Excel workbooks open. If there are then I just want to close the activeworkbook for this I'd use activeworkbook.close. If there are not then I can use application.quit

How do I check to see if there are any other Excel workbooks open?

I have been using application.quit with messages surpressed. Alas someone had other workbooks open and had done a lot of work, opened my workbook, ran a macro and application.quit closed not only my workbook but theirs as well and they lost their work. ooppss!

smiler44
 
Hi, smiler,

this should get you going:
Code:
Sub smiler()
Dim blnPersonal As Boolean
Dim wb As Workbook
For Each wb In Workbooks
    'check for the personal macro workbook
    If InStr(1, "personl", wb.Name) > 0 Then blnPersonal = True
Next wb
' as a booelan value of TRUE delivers -1 subtraction is used
If Workbooks.Count > (1 - blnPersonal) Then
    MsgBox "other workbooks are open"
Else
    Application.Quit
End If
End Sub
Ciao,
Holger
 
Thank you Mr. B
woosh, it went over my head. When things I think should be easy get that complicated I get lost. Need a day when time is on my side to try and understand it.
smiler44
 
Don't hesitate to just ask questions when you don't understand. We've all been there and done that.
 
Hi, Mr. B,

AFAIK each instance of Excel running on a machine is isolated from each other one so only workbooks in one instance will ask for any action before closing down (Application.Quit) while all other instances are not affected. We´re talking about Excel Application.Quit and not Windows API or WMI ShutDown, are we?

Ciao,
Holger
 

Users who are viewing this thread

Back
Top Bottom