After a previous question, I have this code called at the end of a Workbook Open 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.
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.