-
That's what I thought you meant. Sorry, I was just trying to make it obvious for anyone else who was trying to learn from this post.
I've played with the ontime method for different reasons, so I wouldn't want it to keep going if a user opened another wb.
Your code should be good as is. :yes
-
Hi Ken,
this is the final code. I have submited it to the KB to help others.
At This_Workbook:
[VBA]
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Call Limpa
End Sub
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Call Timer
End Sub
Private Sub Workbook_SheetDeactivate(ByVal Sh As Object)
' If you dont want to close the workbook while you are using another one
' simply enable this by removing the " ' " before "Call Limpa"
' if you dont do that the application will be closed even if you are
' working at another workbook
'Call Limpa
End Sub
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
Call Timer
End Sub
[/VBA]
At Module1:
[VBA]
Public vartimer As Variant
Sub Timer()
Call Limpa
vartimer = Format(Now + TimeSerial(0, 30, 0), "hh:mm:ss")
If vartimer = "" Then Exit Sub
Application.OnTime TimeValue(vartimer), "Fecha"
End Sub
Sub Fecha()
With Application
.EnableEvents = False
ActiveWorkbook.Save
.Quit
End With
End Sub
Sub Limpa()
On Error Resume Next
Application.OnTime earliesttime:=vartimer, _
procedure:="Fecha", schedule:=False
On Error GoTo 0
End Sub
[/VBA]