When AutoSave is enabled, this BeforeSave code runs automatically on a periodic basis even if the user is in the middle of something else (such as typing data into a cell), which could be extremely annoying. When AutoSave is off, the user gets to choose when he or she wants to save, and therefore, even though the add-in slows down the save process slightly, the user does not notice. This process might take a second to complete, and Excel could be unresponsive while this is happening. Such an add-in might have BeforeSave code that serializes any maps that the user has created and stores them in the workbook in a CustomXML part. Imagine an add-in that allows the user to create custom maps based on data in an Excel workbook.
When AutoSave is enabled, this code runs automatically on a periodic basis, which has the potential to interrupt the user, especially if the code takes a long time. When AutoSave is disabled, this code is only run when the user explicitly chooses to save, so a delay is not as noticeable and can be avoided by the user until he or she is ready to save. Therefore, if your code in a BeforeSave or AfterSave event handler takes too long to run, it may significantly degrade the user experience. In general, Word, Excel and PowerPoint are not responsive to user interaction while add-in or macro code is being run. Issue 1: Code in BeforeSave or AfterSave events runs too long Code in BeforeSave cancels the file save (by setting Cancel argument to True).Code in AfterSave dirties the workbook (Excel only).Code in save events clears the undo stack (Excel only).Code in save events surfaces a modal dialog.Code in BeforeSave or AfterSave events runs too long.You may need to handle one or more of the following issues regarding the interaction between save events and AutoSave: Potential issues with save events and AutoSave MsgBox "This workbook is being saved automatically: " & ActiveWorkbook.AutoSaveOn This example turns off AutoSave and notifies the user that the workbook is not being automatically saved. You can also take steps as a developer to mitigate these problems so that your add-ins and macros work smoothly, even if AutoSave is enabled. You can do this on the user’s behalf by using the AutoSaveOn property in Word, Excel, and PowerPoint if it's available (see the following example). In general, these issues can be avoided if the user chooses to disable AutoSave. Because of this, add-ins and macros that leverage these events may experience problems when AutoSave is on. When AutoSave is enabled, these events fire automatically on a periodic basis without user interaction. Excel also provides an AfterSave event that can execute macro or add-in code after the save completes. If AutoSave is turned off, save must be triggered manually for the user's changes to be persisted in the cloud and for this user to receive others' changes.Ĭurrently, Excel, Word, and PowerPoint provide a BeforeSave event that allows a developer to execute code after the user triggers a save but before the save occurs. When the file is shared with others, their changes are merged into this user's version of the file. When a file is hosted in the cloud (that is, OneDrive, OneDrive for Business, or SharePoint Online), AutoSave enables the user's edits to be saved automatically and continuously.
Learn about how AutoSave works in Excel, PowerPoint, and Word, and how it can impact add-ins or macros.