Option Explicit
Public RunWhen As Double
Option Explicit
Private Sub Workbook_AfterSave(ByVal Success As Boolean)
On Error Resume Next
If Not IsNull(RunWhen) Then
'cancel current timer
CancelEarly
'start new timer
StartSaveTimer
End If
End Sub
Private Sub Workbook_Open()
If Not ActiveWorkbook.ReadOnly Then
StartSaveTimer
End If
End Sub
Option Explicit
Public RunWhen As Double
Sub StartSaveTimer()
RunWhen = Now + TimeValue("00:10:00")
Application.OnTime RunWhen, "AskToSave", , True
End Sub
Sub AskToSave()
If MsgBox("Do you want to save?" & Chr(10) & Chr(13) & Chr(10) & Chr(13) & "Select Yes to Save, Select No to be reminded Later" & Chr(10) & Chr(13) & Chr(10) & Chr(13) & "Last save was at " & ThisWorkbook.BuiltinDocumentProperties(12), vbYesNo, "Time to Save Master File") = vbYes Then
' the after save event also re-starts the timer
ThisWorkbook.Save
Else
StartSaveTimer
End If
End Sub
Sub CancelEarly()
On Error Resume Next
Application.OnTime RunWhen, "AskToSave", , False
End Sub
Private Sub Workbook_Open()
If Not ActiveWorkbook.ReadOnly Then
wbToSave = ActiveWorkbook
StartSaveTimer
End If
End Sub
Option Explicit
Public RunWhen As Double
Public wbToSave As Workbook
Sub StartSaveTimer()
RunWhen = Now + TimeValue("00:10:00")
Application.OnTime RunWhen, "AskToSave", , True
End Sub
Sub AskToSave()
If MsgBox("Do you want to save?" & vbCrLf & vbCrLf & "Select Yes to Save, Select No to be reminded Later" & vbCrLf & vbCrLf & "Last save was at " & ThisWorkbook.BuiltinDocumentProperties(12), vbYesNo, "Time to Save Master File") = vbYes Then
' the after save event also re-starts the timer
wbToSave.Save
Else
StartSaveTimer
End If
End Sub
Sub CancelEarly()
On Error Resume Next
Application.OnTime RunWhen, "AskToSave", , False
End Sub