Public re_time1 As Double
Public re_time2 As Double
Public re_time3 As Double
Public Const Time_Seconds1 = 270 '270 seconds to show msg box
Public Const t_bao = "InfoBox"
Public Const close_file = "SaveClose"
Public book_server As Workbook
Sub StartTimer1() 'msg box
re_time1 = Now + TimeSerial(0, 0, Time_Seconds1)
re_time3 = Now + TimeSerial(0, 0, Time_Seconds1 + 32)
Application.OnTime EarliestTime:=re_time1, Procedure:=t_bao, _
Schedule:=True
End Sub
Sub StartTimer2() 'close file
Set book_server = ActiveWorkbook
re_time2 = Now + TimeSerial(0, 0, 30) 'after 30 seconds
Application.OnTime EarliestTime:=re_time2, Procedure:=close_file, _
Schedule:=True
End Sub
Public Sub StopTimer() '
On Error Resume Next
Application.OnTime EarliestTime:=re_time3, Procedure:=close_file, _
Schedule:=False
End Sub
Public Sub SaveClose()
Dim wb As Workbook
For Each wb In Workbooks
If wb.Name = book_server.Name Then
Set wb = Application.Workbooks(book_server.Name)
wb.Close SaveChanges:=True
End If
Next
End Sub
Public Sub InfoBox()
Dim t As Integer, InfoBox As Object
Dim tb As Integer
Set InfoBox = CreateObject("WScript.Shell")
'Set the message box to close after 2 seconds
t = 2
Select Case InfoBox.popup("This file will close after 30 seconds.", _
t, "Msg Box", 0)
Case 1, -1
Call StartTimer2
End Select
End Sub