Created
August 5, 2020 20:06
-
-
Save m8urnett/47a0bc274dc1fb5a3610b043fb25d904 to your computer and use it in GitHub Desktop.
VBA auto save
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'----------------------------------------------------------------------------- | |
' 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