bruce42392
New Member
- Joined
- Feb 3, 2016
- Messages
- 3
I am using TaskScheduler to open a spreadsheet to run an Autpen subroutine. The Autpen subroutine calls various subroutines to pull data from a server, perform calculations, update charts, export pdfs, and send emails. At the end of Autpen, a timed popup allows user intervention to stop the program from closing OR automatically closes the program until TaskScheduler runs it the next day. My code worked fine for about 2 years, but now, Application.DisplayAlerts=False & ActiveWorkbook.Saved=True are not preventing the "Do you want to save before closing" prompt when Application.Quit is executed. The "save?" prompt does not appear for ActiveWorkbook.Close, but the Excel application window remains open after the workbook closes. I am using Excel 2010.
The ultimate goal is to have TaskScheduler open the spreadsheet, have the workbook update itself, and have the workbook/excel close.
Here is a copy of the code that is not working properly.
Application.DisplayAlerts = False
Application.Calculation = xlCalculationAutomatic
Select Case CreateObject("WScript.Shell").Popup("Do you want to close this workbook? No response will be interpreted as YES in 5s.", 7, "Close Workbook?", vbYesNo)
Case vbYes, 1, -1
If Workbooks.Count > 1 Then
ActiveWorkbook.Close SaveChanges:=True
Else
ActiveWorkbook.Save
Debug.Print "Saved = " & ActiveWorkbook.Saved
Debug.Print "Disp Alerts = " & Application.DisplayAlerts
Application.Quit
End If
Case vbNo
MsgBox ("You may close the workbook when ready.")
End Select
Application.Calculation = xlCalculationAutomatic
Application.DisplayAlerts = True
End Sub
The ultimate goal is to have TaskScheduler open the spreadsheet, have the workbook update itself, and have the workbook/excel close.
Here is a copy of the code that is not working properly.
Application.DisplayAlerts = False
Application.Calculation = xlCalculationAutomatic
Select Case CreateObject("WScript.Shell").Popup("Do you want to close this workbook? No response will be interpreted as YES in 5s.", 7, "Close Workbook?", vbYesNo)
Case vbYes, 1, -1
If Workbooks.Count > 1 Then
ActiveWorkbook.Close SaveChanges:=True
Else
ActiveWorkbook.Save
Debug.Print "Saved = " & ActiveWorkbook.Saved
Debug.Print "Disp Alerts = " & Application.DisplayAlerts
Application.Quit
End If
Case vbNo
MsgBox ("You may close the workbook when ready.")
End Select
Application.Calculation = xlCalculationAutomatic
Application.DisplayAlerts = True
End Sub