I've used a similar method to this answer to force users to use a certain button to save. I have the following:
public variable
Dim MacroSave As Boolean
button event
Sub RealSave_Click()
MacroSave = True
ThisWorkbook.Save
MacroSave = False
End Sub
save catcher
Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
If Not MacroSave Then
Cancel = True 'Cancels any request to save the file
MsgBox "Workbook not saved."
Else
Ret = MsgBox("Are you sure you want to save?", vbCritical Or vbYesNo, "Save File?")
If Ret = vbNo Then Cancel = True
End If
End Sub
sadness
The above code worked perfectly for some amount of time, but now it's telling me Code execution has been interrupted
at MacroSave = False
. If I hit Continue
on the error pop-up, the file has saved fine. I can't see anything not working properly; it's just this pesky pop-up.
I tried
adding
DoEvents
beforeMacroSave = False
(and afterThisWorkbook.Save
), but the code was interrupted onDoEvents
.moving that line to the "save catcher", but the same error came up on the
End Sub
for the button event.On Error Resume Next
, which does not eliminate this issue.