Albin
Albin

Reputation: 1110

Turn off autosave in vba (Excel/OneDrive)

I'm trying to turn off the autosave function for my excel document (Excel 365 while saving the file on OneDrive):

enter image description here

Doing a little research AutoRecover.Enabled = False (Application.) should be the right attribute but for some reason I can't get it to work. I don't get an error message, but the AutoSave Function does not turn off.

No luck with different objects (myWorkbook.AutoRecover.Enabled = False, etc.) either. Any Ideas what the problem might be?

Upvotes: 10

Views: 34882

Answers (2)

Sgdva
Sgdva

Reputation: 2800

Enhancing Any1There Solution
I just saw the need of reviving this post with an updated answer to create it as a mandatory function whenever you are working with workbooks on O365

Sub Exec_Example()
    ...
    Set WBToWorkIn = Workbooks.Open(TxtFilePath): DoEvents
    Call Exec_TurnAutoSave(False,WBToWorkIn)
    ...
End Sub
Sub Exec_TurnAutoSave(IsTurnAutoSaveOn As Boolean, Optional ByVal WBToTurn As Workbook)
If WBToTurn Is Nothing Then Set WBToTurn = ThisWorkbook
Dim IsAutoSaveOn As Boolean
    If Val(WBToTurn.Parent.Version) > 15 Then WBToTurn.AutoSaveOn = IsTurnAutoSaveOn
    Set WBToTurn = Nothing
End Sub

Justification
With larger deployment of O365, this is usually set on by default, and it seems to crash Excel instance randomly when debugging/on coding execution.The safest path is to turn it off whenever you are dealing with the WB itself in your coding.

Upvotes: 0

Any1There
Any1There

Reputation: 206

This code checks whether autosave in Excel 365 is on and, if so, turns it off. It displays messages indicating the status before and after the change.

Note: The below code only works for office 365 subscribers and in Excel 2016 or later

Sub ChkAutoSv()
Dim AutoSv As Boolean

    If Val(Application.Version) > 15 Then
        AutoSv = ActiveWorkbook.AutoSaveOn
        MsgBox "AutoSave set to: " & AutoSv
        If AutoSv Then ActiveWorkbook.AutoSaveOn = False
        AutoSv = ActiveWorkbook.AutoSaveOn
        MsgBox "AutoSave now set to: " & AutoSv
    End If
End Sub

Upvotes: 15

Related Questions