Prevent saving workbook

wmtsub

Active Member
Joined
Jun 20, 2018
Messages
322
So I thought if I placed this code into the Workbook Module it would prevent the workbook from being saved or saved as. What did I miss?


Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Application.DisplayAlerts = False
ThisWorkbook.Saved = True
Application.DisplayAlerts = True

End Sub
 
I get a dialog box asking of I want to save the workbook. it will not save so I have to hit cancel to continue. I tried to add more code but it is now giving me issues again when saving.
I open the file with the SHIFT key add code and it will not save. If I rem the cancel line then I can. Reopen and remove the rem and I can not save …..ARG. Is there another way to disable macros when opening the workbook?

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
' Cancel = True
DisplayAlerts = False
ThisWorkbook.Saved = True
 
Upvote 0

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Found the solution, I have to open the file from an existing open excel instance, not the actual workbook or shortcut
 
Upvote 0

Forum statistics

Threads
1,214,929
Messages
6,122,314
Members
449,081
Latest member
tanurai

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