Why do all Excel processes not close

Steve_R

Active Member
Joined
Oct 28, 2015
Messages
350
After a previous question, I have this code called at the end of a Workbook Open sub.
Code:
Sub inactivityShellPopUp()
Const ShowDurationSecs As Integer = 10
    Select Case CreateObject("WScript.Shell").PopUp( _
                    "This program will close in " & _
                    ShowDurationSecs & " seconds." & vbCrLf & _
                    "Do you want it to close now?", ShowDurationSecs, _
                    "Message Title", 4 + 32)
        Case -1, 6
            'My part
            For Each w In Application.Workbooks
                w.Save
            Next w
            Application.Quit
            'end my part
                       
            
        Case Else
    End Select
End Sub

After a few days trying to debug this is getting a little frustrating!
I have been having issues running code in the WB (e.g. a caller sub may run no subs or the first sub called but no subsequent subs. Pressing F5 may do the same press but it always steps all the way through all subs using F8).
After copying all modules and sheets to a new WB and saving that, the first Workbook Open did not fire the code (I suspect a previous code module from a closed WB caused issues - read on).

I decided to have a look at Windows tasks. With All Excel windows closed, it showed two Excel.Exe processes. I terminated these and opened the new workbook. The workbook open code ran as it should. I closed the WB and opened it again, checked and found two Excel.exe processes. Without terminating these, the workbook open code ran as it should. A few more tests, including allowing code to close the WB or manually closing it myself resulted in the workbook code doing as it should. However, I am confused the Application.Quit is not ending all Excel processes and am still wondering whether calling the WB as a Windows task may be causing issues and wish to beef up the code to minimise the chance this will happen. Consequently, I am wondering whether terminating all excel processes is possible instead of Application.Quit.

I tried adding w.close after w.save but that seems to leave Excel running with no workbook open.
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Sorry. The code kept working perfectly until just now when I started working on another module then the same symptoms recurred in that module and the workkbook open code then started failing (whether or not excel processes were closed). Each sub works there but it does not proceed to the second sub when called. There is no error message and I can run other code (i.e. it thinks execution is complete). Stepping through with F8 runs the code to completion. Looks like the kay to the problem is in that module and not connected with excel processes remaining open. I plan to revise/re-write all code in that module instead.
 
Upvote 0

Forum statistics

Threads
1,215,772
Messages
6,126,803
Members
449,337
Latest member
BBV123

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