View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
puba puba is offline
external usenet poster
 
Posts: 7
Default OnTime+TimeValue + Autoclose

This workbook
-------------

Private Sub Workbook_BeforeClose(Cancel As Boolean)
MsgBox "Closing timer: " & nextime
On Error GoTo xxx
Application.OnTime nextime, "chkexit", , False
MsgBox "timer cancelled"
Exit Sub
xxx:
MsgBox "error while cancelling the timer"
End Sub

Private Sub Workbook_Open()
delay = TimeValue("00:00:50")
nextime = Now + delay
MsgBox "You will get a prompt for saving and exiting after " & delay &
" which is at " & nextime
Application.OnTime nextime, "chkexit", , True

End Sub



module1
--------
'Type the following two lines in the declarations section
Public nextime As Date
Public delay As Date

Sub chkexit()
If MsgBox("The timer " & nextime & " has elapsed.Do you want to
continue working", vbYesNo) = vbYes Then
nextime = Now + delay
MsgBox "You will get another prompt in " & delay & "which is at " &
nextime
Application.OnTime nextime, "chkexit", , True
Else
ActiveWorkbook.Close
End If
End Sub