Skip to content

Instantly share code, notes, and snippets.

@m8urnett
Created August 5, 2020 20:06
Show Gist options
  • Save m8urnett/47a0bc274dc1fb5a3610b043fb25d904 to your computer and use it in GitHub Desktop.
Save m8urnett/47a0bc274dc1fb5a3610b043fb25d904 to your computer and use it in GitHub Desktop.
VBA auto save
'-----------------------------------------------------------------------------
' Auto save because Microsoft forces you to use OneDrive for autosave now
' Instructions:
' 1. Show the Developer ribbon
' 2. Go into Visual Basic
' 3. Add a new module in Normal
' 4. Paste this code there
Const MINUTES_INTERVAL = 5 'Set the desired interval, in minutes
Public Sub Document_Open()
Application.OnTime DateAdd("n", MINUTES_INTERVAL, Now), "AutoSaver"
End Sub
Private Sub AutoSaver()
For Each CurrentDoc In Documents
StatusBar = "Auto saving..."
'Debug.Print "Saving " & CurrentDoc.Name & "..."
With CurrentDoc
'Only save if it needs saving
If Not .Saved And Not .ReadOnly Then
.Save
'Verify successful save
If not .Saved Then
StatusBar = "Error saving " & .Name & ": " & Err.Description
End If
End If
End With
DoEvents
Next
'Set schedule for next auto save
Application.OnTime DateAdd("n", MINUTES_INTERVAL, Now), "AutoSaver"
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment