Use beforesave event to cancel save

gschwint

Board Regular
Joined
Aug 17, 2004
Messages
121
I have created a userform that captures via a public variable if a save of the workbook is desired or not. I attempt to use this public variable result within the workbook beforesave event to either save the workbook or cancel the save (exit the beforesave event). Here is the code that I think should work but it doesn't as the workbook is saved in all instances.

Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

Proper_Save.Show 'call userform to get public variable "savequestion" result

If savequestion = True Then 'exit the default save and go back to the program
Cancel = True
Exit Sub
End If

End Sub


I have found that the public variable approach works good and is working properly by returning the correct result (true/false) but the workbook is saved regardless of the result. Any ideas???
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

Forum statistics

Threads
1,224,574
Messages
6,179,634
Members
452,934
Latest member
Jdsonne31

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top