PDA

View Full Version : Vba, How can code the excel file to save as only and disable to save directly file



Mawar5530
05-13-2020, 06:10 AM
Hi Friends,

Please help to share vba macro code.

georgiboy
05-19-2020, 06:51 AM
Hi Mawar,

This may not be the best solution but it will give you a start.
Keep in mind that if the user chooses not to enable macros then they will be able to save the workbook.

The solution below will prevent the save and instead offer the save as dialogue.


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

If Not SaveAsUI Then
Cancel = True
MsgBox "You cannot save this workbook, save as only"
Application.Dialogs(xlDialogSaveAs).Show
End If

End Sub

This code will need to go into the "ThisWorkbook" code window.

Hope this helps

Jan Karel Pieterse
05-19-2020, 08:26 AM
Alternatively you could set a password to modify the file. If password is not entered, the file is read-only. No VBA required.