Cannot start the "Want to save changes" dialog in Excel

  • In Word VSTO, we have a DocumentBeforeSave event, which is called immediately after the “I want to save your changes” dialog, and I can easily cancel the standard “Save” dialog and show my own.

  • But in Excel, VSTO WorkbookBeforeSave is called after closing the Save dialog box, after which it opens after creating the built-in My Settings dialog box. I can use the WorkbookBeforeClose event, but I have to show my "I want to save your changes" dialog, and the autosave function will not work when I click "Do not save."

Is there a way to call my code immediately after the “Want to save changes” dialog in Excel with the option to prevent the built-in “Save” dialog or somehow tell Excel to create an autosave point (with my own “Want to save your changes”) when I I click "Do not save"?

+6
source share
1 answer

I'm not sure if you found your answer, as this thread is a bit outdated, but I thought I would bet my $ 0.02.

I create a named range [isDirty] on an unlocked, very dangerous worksheet and on every visible worksheet. Change the setting [isDirty] = True

In Workbook.BeforeClose, I have the following:

If [IsDirty] = True Then Select Case MsgBox("Do you want to save the changes you made to '" & .Name & "'?", _ vbYesNoCancel + vbExclamation) Case Is = vbYes ThisWorkbook.Save [IsDirty] = False Case Is = vbNo 'Do not save Case Is = vbCancel Cancel = True End Select End If 

In Private Sub Workbook_BeforeSave (ByVal SaveAsUI As Boolean, Cancel As Boolean)

  ThisWorkbook.Save [IsDirty] = False Cancel=True 
0
source

Source: https://habr.com/ru/post/978501/


All Articles