Share via

Macro to disable save as function

Anonymous
2014-07-09T18:53:59+00:00

I have the following macro to disable the save as function in excel.  Is it possible to add to it to have a macro box pop up so that a password could be entered to bypass the macro and be able to save as

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

'This macro disables the "Save As" Feature in Excel 'This means that a user will not be able to save this 'workbook(file) under a different name or in a different location ' 'This MUST be placed in "ThisWorkbook" and NOT in a Module. '

    If SaveAsUI = True Then Cancel = True

End Sub `

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

HansV 462.6K Reputation points
2014-07-09T19:03:20+00:00

You could use

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

'This macro disables the "Save As" Feature in Excel

'This means that a user will not be able to save this

'workbook(file) under a different name or in a different location

'

'This MUST be placed in "ThisWorkbook" and NOT in a Module.

'

    Const strPassword = "secret" ' the password to unlock Save As

    If InputBox("Enter the password to display the Save As dialog, or click Cancel") <> strPassword Then

        If SaveAsUI = True Then Cancel = True

    End If

End Sub

It would be a good idea to password-protect the VBA code too, otherwise anyone can see the password in the code. To do so, select Tools > VBAProject Properties in the Visual Basic Editor, activate the Protection tab, tick the check box "Lock project for viewing", enter the password you want to use in both boxes and click OK. Do not forget this password!

Warning: if the user disables macros, the above code won't run, so the user will be able to use Save As without restrictions.

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

0 additional answers

Sort by: Most helpful