简体   繁体   English

在 vba (Excel/OneDrive) 中关闭自动保存

[英]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):我正在尝试为我的 excel 文档关闭自动保存 function(Excel 365,同时将文件保存在 OneDrive 上):

在此处输入图像描述

Doing a little research AutoRecover.Enabled = False ( Application. ) should be the right attribute but for some reason I can't get it to work.做一些研究AutoRecover.Enabled = False ( Application. ) 应该是正确的属性,但由于某种原因我无法让它工作。 I don't get an error message, but the AutoSave Function does not turn off.我没有收到错误消息,但 AutoSave Function 没有关闭。

No luck with different objects ( myWorkbook.AutoRecover.Enabled = False , etc.) either.不同的对象( myWorkbook.AutoRecover.Enabled = False等)也没有运气。 Any Ideas what the problem might be?任何想法可能是什么问题?

This code checks whether autosave in Excel 365 is on and, if so, turns it off.此代码检查 Excel 365 中的自动保存是否已打开,如果是,则将其关闭。 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注意:以下代码仅适用于 Office 365 订阅者和 Excel 2016 或更高版本

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

Enhancing Any1There Solution增强 Any1There 解决方案
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我刚刚看到需要使用更新的答案来恢复这篇文章,以便在您使用 O365 上的工作簿时将其创建为强制性 function

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.随着 O365 的较大部署,这通常默认设置为打开,并且在调试/编码执行时似乎会随机崩溃 Excel 实例。最安全的方法是在编码中处理 WB 本身时将其关闭。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM