It works! So i added an extra part that closes the workbook after 15min, so the splash screen will serve as a warning that 10min are up and 5min remaining before a save close event is forced.
This will prevent the users from "hogging" the file.
here's the final working code
In workbook:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
StopTimer
End Sub
Private Sub Workbook_Open()
StartTimer10min
StartTimer15min
End Sub
In my module:
Public RunWhen As Double
Public RunWhen2 As Double
Public Const cRunIntervalSeconds10 = 600 '10min
Public Const cRunWhat10 = "MsgPrompt" ' the name of the procedure to run
Public Const cRunIntervalSeconds15 = 900 '15min
Public Const cRunWhat15 = "CloseAll" ' the name of the 2nd procedure to run
'This program prompts the user after time has met a preset
Sub MsgPrompt()
UserForm2.Show
End Sub
Sub StartTimer10min()
RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds10)
Application.OnTime EarliestTime:=RunWhen, Procedure:=cRunWhat10, _
Schedule:=True
End Sub
Sub StartTimer15min()
RunWhen2 = Now + TimeSerial(0, 0, cRunIntervalSeconds15)
Application.OnTime EarliestTime:=RunWhen2, Procedure:=cRunWhat15, _
Schedule:=True
End Sub
Sub KillForm()
Unload UserForm2
End Sub
Sub StopTimer()
On Error Resume Next
Application.OnTime EarliestTime:=RunWhen, Procedure:=cRunWhat10, _
Schedule:=False
On Error Resume Next
Application.OnTime EarliestTime:=RunWhen2, Procedure:=cRunWhat15, _
Schedule:=False
On Error Resume Next
Application.OnTime EarliestTime:=Now + TimeValue("00:00:07"), Procedure:="KillForm", _
Schedule:=False
End Sub
Sub CloseAll()
'This closes the file, and saves any changes if changes were made
Workbooks("Book1.xls").Close SaveChanges:=True
End Sub
userform code:
Public Sub UserForm_Initialize()
Application.OnTime Now + TimeValue("00:00:07"), "KillForm"
End Sub
Thanks again
Bookmarks