0

I'm creating an excel file and I want to disable the 'save' and 'save as...' option.

I found a lot of solutions on the internet, like this one in VBA:

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
     MsgBox "You can't save this workbook!"
     Cancel = True
End Sub

It prevents user from saving changes, but I can't save my changes and that's the problem because I need to do more changes in the VBA code.

Is there a way to save my macro changes ? Like an administrator mode etc... ?

Thank you for your future answers.

2 Answers 2

1

Use a global variable to override the Save disable:

    Dim override as Boolean

    Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
         if Not(override) then
           MsgBox "You can't save this workbook!"
           Cancel = True
         end if
    End Sub
    Sub SaveMyChanges()
       override = true
       ActiveWorkbook.Save
       override = false
    End Sub
Sign up to request clarification or add additional context in comments.

Comments

0

You can also save while in Design Mode in VBA.

Sorry for the necro, but this works also and is what I do.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.