I applied a looping autosave macro script to a workbook last Tuesday and it worked no problem. I come back in today and the last save was at 1:37 am (this morning). I run the script manually and it doesn’t loop. Also when I try to close the workbook Excel will hang up indefinitely. I can’t figure out what went wrong. Anybody have any idea? Code below:
Option Explicit
Private dtScheduled As Date
Private Sub Workbook_Open()
ScheduleSaving
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
On Error Resume Next
Application.OnTime dtScheduled, "ThisWorkbook.DoSave", Schedule:=False
End Sub
Private Sub ScheduleSaving()
dtScheduled = Now + TimeSerial(0, 5, 0)
Application.OnTime dtScheduled, "ThisWorkbook.DoSave"
End Sub
Sub DoSave()
On Error Resume Next
ThisWorkbook.Save
ScheduleSaving
End Sub
New contributor
Colored_Red is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.