Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
if (the time is 10mins after the time recorded) Then
X=MsgBox ("Text to Display","VbYesNo")
if X=VbYes Then
Activeworkbook.save
(Set the time value in the cell you have chosen)
End If
End If
End Sub
Option Explicit
Private Sub workbook_OnOpen()
Dim basetime As Date
Set basetime = Now
End Sub
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
Dim msg As Long
If ThisWorkbook.ReadOnly Then
Exit Sub
End If
If (Now - basetime) > (10 / 1440) Then
msg = MsgBox("It is time to save your work. Save Now?", vbOKCancel, "Save your work!")
If msg = vbOK Then
ActiveWorkbook.Save
Set basetime = ThisWorkbook.BuiltinDocumentProperties(12)
ElseIf msg = vbCancel Then
Set basetime = Now
End If
End If
End Sub
Private Sub Workbook_Open()
StartSaveTimer
End Sub
Option Explicit
Dim RunWhen As Double
Sub StartSaveTimer()
RunWhen = Now + TimeValue("00:10:00")
Application.OnTime RunWhen, "AskToSave", , True
End Sub
Sub AskToSave()
Select Case _
MsgBox("Do you want to save?", vbYesNoCancel, "To save or not to save, that is the question.")
Case vbYes
'your save code
Case vbCancel
Exit Sub ' don't restart timer
Case Else
'do nothing.
End Select
'restart the timer
StartSaveTimer
End Sub
Sub CancelEarly()
Application.OnTime RunWhen, "AskToSave", , False
End Sub
Option Explicit
Dim RunWhen As Double
Sub StartSaveTimer()
RunWhen = Now + TimeValue("00:[COLOR=#ff0000]01[/COLOR]:00")
Application.OnTime RunWhen, "AskToSave", , True
End Sub
Sub AskToSave()
Select Case _
MsgBox("Do you want to save?", [COLOR=#ff0000]vbOKCancel[/COLOR], "To save or not to save, that is the question.")
Case [COLOR=#ff0000]vbOK[/COLOR]
'your save code
[COLOR=#ff0000] ThisWorkbook.Save[/COLOR]
[COLOR=#ff0000] StartSaveTimer[/COLOR]
[COLOR=#ff0000]Case vbCancel[/COLOR]
[COLOR=#ff0000] StartSaveTimer[/COLOR]
Case Else
'do nothing.
End Select
'restart the timer
StartSaveTimer
End Sub
Sub CancelEarly()
Application.OnTime RunWhen, "AskToSave", , False
End Sub
Option Explicit
Dim RunWhen As Double
Sub StartSaveTimer()
RunWhen = Now + TimeValue("00:00:05")
Application.OnTime RunWhen, "AskToSave", , True
End Sub
Sub AskToSave()
If MsgBox("Do you want to save?", vbYesNo, "To save or not to save, that is the question.") = 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
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