check Excel instance and terminate
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 4 of 4

Thread: check Excel instance and terminate

  1. #1
    New Member
    Join Date
    Feb 2002
    Location
    ]-[ /-\ \/\/ /-\ | | ~~~@|_()]-[/-\!!!
    Posts
    48
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

     
    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)

  2. #2
    MrExcel MVP Russell Hauf's Avatar
    Join Date
    Feb 2002
    Location
    Portland, OR Area - USA
    Posts
    1,605
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    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 ]

  3. #3
    New Member
    Join Date
    Feb 2002
    Location
    ]-[ /-\ \/\/ /-\ | | ~~~@|_()]-[/-\!!!
    Posts
    48
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    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!

  4. #4
    Board Regular
    Join Date
    Mar 2002
    Location
    Keaau, Hawaii
    Posts
    238
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

      
    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 ]

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

 

 
DMCA.com