Sunday, June 7, 2015

Prevent save as in Excel

The code below can be used to stop any users saving a Workbook as another name and another location.
The code must be placed in the Private Module of the Workbook Object (ThisWorkbook). The fastest way to get there is to right click on the Excel icon, top left next to File and select View Code. It is in here you should place the code below and then save the Workbook. So long as the Workbook is opened with macros enabled the code will fire anytime any user tries to use Save As.
 
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

 If SaveAsUI = True Then Cancel = True

End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)

    Application.ThisWorkbook.Saved = True 'Tells Excel that the _
file has already been saved (this prevents Excel from requesting _
that you save the file when you close it)

End Sub
  Source 
http://www.excel-pratique.com/en/vba_tricks/preventing_a_file_from_being_saved.php 
http://www.ozgrid.com/VBA/prevent-save-as.htm

No comments:

Post a Comment