Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Disable Save and Save As using VBA

Tags:

excel

vba

I am writing a macro and I need to disable the save function on the workbook that VBA has copied and pasted all the information into. Is this possible?

like image 640
Hannah Avatar asked Sep 04 '12 13:09

Hannah


People also ask

How do you disable Save and Save As option in Excel VBA?

VBA 1: disable the Save & Save As options in Excel In the opening Save As window, select a folder to save the workbook, name the workbook as you need and select Excel Macro-Enabled Workbook from the Save as type drop-down list, and finally click the Save button.

How do you stop save prompt in Excel VBA?

VBA Code: To block the SaveAs dialog box prompt from showing, you simply need to toggle off the Display Alerts application setting prior to using the SaveAs command.

How do I restrict a save in Excel?

Restrict changes in Excel For more protection options, click File > Protect Workbook.


1 Answers

You can use the Workbook_BeforeSave event to achieve this, disabling the CommandBars won't stop your users using a shortcut such as CTRL + S.

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

    MsgBox "You can't save this workbook!"
    Cancel = True

End Sub
like image 164
Francis Dean Avatar answered Sep 27 '22 22:09

Francis Dean