Disable Excel save option but allow macro save

5k Views Asked by At

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

There are 2 best solutions below

0
On BEST ANSWER

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
0
On

You can also save while in Design Mode in VBA.

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