Consulting

Results 1 to 5 of 5

Thread: Word AutoSave Bypass?? (Word 2013)

  1. #1

    Question Word AutoSave Bypass?? (Word 2013)

    I currently have a macro that runs at the BeforeSave event to create a copy of the document and also print the document to PDF. I have it planned to be ran as a global template, and for that reason I have a userform that prompts the user if they want to save with the macro, cancel, or save normal without the macro. This way the user is able to save documents normally if the documents aren't going to be used for work purposes. I thought I had everything figured out until the autosave feature ran after 10 minutes and triggered the macro to run. This would be very annoying to have the userform pop-up every 10 minutes.
    Currently, I bypass the macro if the SaveAs is triggered. Is there a way to recognize the autosave event and let it bypass the macro the same way as the SaveAs? I figured the entire code is not necessary, so I only included the beginning to capture what I was referring too above.

    I realize I can disable the auto save feature in Word, but I have a feeling that IT and many users would like to keep it turned on for safety reasons. I'm just trying to figure out my other options at this point.

    Private Sub App_DocumentBeforeSave(ByVal Doc As Document, SaveAsUI As Boolean, Cancel As Boolean)
        If SaveAsUI Then
            GoTo lbl_End
        Else
    'All other code
    End Sub
    As always, thank you for the help!

  2. #2
    VBAX Expert Dave's Avatar
    Joined
    Mar 2005
    Posts
    832
    Location
    Can't you just go File>Options>Save then uncheck the autodocument recovery feature in the Global document? Dave

  3. #3
    VBAX Expert Dave's Avatar
    Joined
    Mar 2005
    Posts
    832
    Location
    I re-read this post and I see that it's not so simple when there's IT folks around. My mistake so I Googled a bit and found some code and some insights to a possible solution. Word VBA's not my thing so I'm no sure this will be helpful. Dave
    'use this method to verify is the Save triggered by user or is it AutoSave:
    'It works fine with Word 2010 on Windows 7 but on Windows 8.1 it does not work.
    void adxWordEvents_DocumentBeforeSave(object sender, ADXHostBeforeSaveEventArgs e)
    {
    object oBasic = WordApp.WordBasic;
    object fIsAutoSave =
    oBasic.GetType().InvokeMember(
    "IsAutosaveEvent",
    BindingFlags.GetProperty,
    null, oBasic, null);
    if (int.Parse(fIsAutoSave.ToString()) != 1)
    {
    getActiveAddinInstance().getAnnotator().setActive(false);
    }
    }
    'The other way is to intercept all Ribbon controls causing Word to save the document
    '(and produce DocumentBeforeSave). In the event handlers you set a flag and check the
    'flag in the DocumentBeforeSave event: if the flag is not set, the event is initiated by AutoSave.
    'The idea is to have the flag set whenever a user-initiated action occurs; if the flag is not set
    'in DocumentBeforeSave, then the action is intiated by Word itself.
    HTH.

  4. #4
    VBAX Regular
    Joined
    Feb 2018
    Posts
    7
    Location
    nvkjvjk

  5. #5
    You can disable the autosave in Office 16 using a registry hack. That can be called from your process (or separately) and will hold until you change it back with the following function that will toggle the setting. The function will return True if autosave is disabled or false if not.

    Function AutoSaveDisabled() As Boolean
    Dim wshShell As Object
    Dim RegKey As String
    Dim rKeyWord As String
    Dim wVer As String
        Set wshShell = CreateObject("WScript.Shell")
        If Val(Application.Version) < 16 Then
            'The security issue relates to
            'Word versions from 16.0 (Word 365)
            MsgBox "This macro is for Word 2016 and later!", vbOKOnly, "Wrong Word Version"
            Exit Function
        End If
        wVer = Application.Version
    Start:
        RegKey = "HKEY_CURRENT_USER\Software\Microsoft\Office\" & wVer & "\Word\"
        On Error Resume Next
        'The registry key does not exist
        rKeyWord = wshShell.RegRead(RegKey & "DontAutoSave")
        If rKeyWord = "" Then
            wshShell.RegWrite RegKey & "DontAutoSave", 0, "REG_DWORD"    'set it at zero
            GoTo Start:    'and read it again
        End If
        If rKeyWord = 1 Then
            wshShell.RegWrite RegKey & "DontAutoSave", 0, "REG_DWORD"
            AutoSaveDisabled = False
        Else
            wshShell.RegWrite RegKey & "DontAutoSave", 1, "REG_DWORD"
            AutoSaveDisabled = True
        End If
    lbl_Exit:
        Exit Function
    End Function
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •