Disable save option on workbook except for named macro's

dan_pafc

Board Regular
Joined
Aug 16, 2007
Messages
162
Hi, I want to disable all save option's in a workbook but still allow 2 macros to save the file.

Im using this to disable the save option:

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

If SaveAsUI = False Then
Cancel = True
MsgBox "You cannot save this workbook. Use Save As"
End If

End Sub

The macros I use to save the book are called Macro1 and Macro2

Kind Regards,

Dan.
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Sorry dmt that doesn really help me.

All i want is for any type of 'save' option to be disabled unless it comes when running either Macro1 or Macro 2, which have save commands in them.
 
Upvote 0
How about creating a global variable and making that varable true before you want to save.

If that varable is true then the save function should allow save, else workbook.saved = true should override the save.

Then reset your varaliable to false.
 
Upvote 0
How about creating a global variable and making that varable true before you want to save.

If that varable is true then the save function should allow save, else workbook.saved = true should override the save.

Then reset your varaliable to false.

thanks dmt - ive found a tempoary solution by adding the following to Macro1 and 2:

Application.EnableEvents = False

then

Application.EnableEvents = True

seems it does what i need it to do.

Thanks for your help dmt.
 
Upvote 0

Forum statistics

Threads
1,215,048
Messages
6,122,862
Members
449,097
Latest member
dbomb1414

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