I needed close a workbook if the user not do workING with it, with two subs i can resolve it
1-put this code into ThisWorkbook
Private Sub Workbook_Open()
'CALL TO "TIME MESSAGE" AFTER THEN 10 MINUTES
Application.OnTime Now + TimeValue("00:10:00"), "TimedMessage"
End Sub
2-put this code into a module
Sub TimedMessage()
Const Title As String = "Self closing message box"
Const Delay As Byte = 5 ' Tps d'affichage en secondes
Const wButtons As Integer = 17 ' Boutons + icone
Dim wsh As Object, msg As String
Set wsh = CreateObject("WScript.Shell")
msg = Space(15) & "Hello," & vbLf & vbLf & "Press ok if you need more time "
wsh.Popup msg, Delay, Title, wButtons
If wsh.Popup(msg, Delay, Title, wButtons) = vbOK Then
Application.OnTime Now + TimeValue("00:10:00"), "TimedMessage"
Else
'SAVE AND CLOSE
Application.DisplayAlerts = False
ThisWorkbook.Save
ThisWorkbook.Close False
End If
Set wsh = Nothing
'
End Sub
when the workbook is opened a timer is launched, and at 10 minutes later (you can change this value) the message appears