check Excel instance and terminate

Joined
Feb 20, 2002
Messages
48
I have an Excel workbook (that has worked normally) that kept crashing on me, closing the program. I figured out the problem: there was a running instance of Excel in the background which was causing this particular workbook to get a housecall from Dr Watson(checked task manager/processes tab and tested theory). I would like to add some vba code to the workbook_open event of this workbook to check if there is a running instance of Excel and to terminate it to prevent this "bug" from coming back. There is a way I have seen, but I don't recall how it's done. Can anyone help me? Much Mahalo!

Aloha!

*(Excel2k/WinNT4 sp6)
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
On 2002-02-27 13:04, ]-[ /-\ \/\/ /-\ | | /-\ |\| wrote:
I have an Excel workbook (that has worked normally) that kept crashing on me, closing the program. I figured out the problem: there was a running instance of Excel in the background which was causing this particular workbook to get a housecall from Dr Watson(checked task manager/processes tab and tested theory). I would like to add some vba code to the workbook_open event of this workbook to check if there is a running instance of Excel and to terminate it to prevent this "bug" from coming back. There is a way I have seen, but I don't recall how it's done. Can anyone help me? Much Mahalo!

Aloha!

*(Excel2k/WinNT4 sp6)

That's a tough one. There is a way to detect if there is an instance of Excel running, but it will detect the instance that your workbook is using (Excel must open before the workbook, right?). Do you know why there was another instance of Excel running? My bet is that it was opened from Code somehow (from another workbook or application, like Access or Word). I suggest that you find whatever is causing a second instance of Excel to open. If you are opening Excel in another application like this:

Dim xl as New Excel.Application
' or
Dim xl as Excel.Application
Set xl = New Excel.Application

then that is most likely where your problem lies. You should either use GetObject or make sure that you close the New instance of Excel when the program is finished:

xl.Quit
Set xl = Nothing

Hope this helps,

Russell
This message was edited by Russell Hauf on 2002-02-27 13:12
 
Upvote 0
Russell,

Don't know if there is another app out there that is launching instance of Excel or not (at least I didn't write any vba to do this). I do have application.quit in thisworkbook object (beforeclose) so that excel closes when the workbook is closed (it's like an "app"). Other than that, I think I will not have an easy time finding out a fix for this(!) Mahalo much anyway!

Aloha!
 
Upvote 0
On 2002-02-27 13:04, ]-[ /-\ \/\/ /-\ | | /-\ |\| wrote:
I have an Excel workbook (that has worked normally) that kept crashing on me, closing the program. I figured out the problem: there was a running instance of Excel in the background which was causing this particular workbook to get a housecall from Dr Watson(checked task manager/processes tab and tested theory). I would like to add some vba code to the workbook_open event of this workbook to check if there is a running instance of Excel and to terminate it to prevent this "bug" from coming back. There is a way I have seen, but I don't recall how it's done. Can anyone help me? Much Mahalo!

Aloha!

*(Excel2k/WinNT4 sp6)

Copy this code to notepad. save the file as XLfinder.vbs
when run it will find any instance of xl that is currently active even if hidden.
I keep mine on the desktop so I dont have to go looking for it.

Dim objXL
Dim strMessage

On Error Resume Next

' Try to grab a running instance of
' Excel...
Set objXL = GetObject(, "Excel.Application")

' What did we find?..
If Not TypeName(objXL) = "Empty" Then
strMessage = "Excel Running."
Else
strMessage = "Excel Not Running."
End If

' Feedback to user...
MsgBox strMessage, vbInformation, "Excel Status"

' Make the Excel instance visible
' if we found one
if strMessage = "Excel Running." then _
objXL.Visible = true

PS Moving to the Big Island in two years see you there.
Visiting for a month this November!!
Aloha
This message was edited by KniteMare on 2002-03-05 13:34
This message was edited by KniteMare on 2002-03-05 13:40
 
Upvote 0

Forum statistics

Threads
1,223,383
Messages
6,171,772
Members
452,423
Latest member
Rene M

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top