Disable Save & Save As Excel 2007

Pretty1996

Board Regular
Joined
Apr 28, 2010
Messages
100
Hi Im hoping someone could help me out here...what Im looking for is help with disable the "save" option in Excel.

Ive got this bit of code

Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
If SaveAsUI Then
MsgBox "The 'Save As' function has been disabled."
Cancel = True
End If
End Sub

This works fine when I select the "Save As" option, however I also want to disable the "Save" option from the file menu and the "Save" button.

Any help or guidance is much appreciated.

Also I am using Excel 2007.
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Just take out the If

Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
MsgBox "The 'Save As' function has been disabled."
Cancel = True
End Sub
 
Upvote 0
Thanks for the reply VoG (Peter?)

much appreciated, I may come back later with more questions :s
 
Upvote 0
Hi, just another question to add to this...

basically what I'm trying to do is this...if you leave a certain cell blank then you should be unable to save the workbook until this criteria has been met.

Ive added to the code slightly so that it looks like...

Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
If Range("A1").Value = "" Then
    Cancel = True
    MsgBox "The 'Save As' function has been disabled."
Else
    Cancel = False
End If
End Sub

Is this the best way to check if a cell value is empty?

Secondly, when "Saving" has been turned off I can't save changes made in my code, it doesnt take much for me to just allowing saving and then amend code...just wondering if there is a work around to this?

Thanks for your help.
 
Upvote 0
You don't need the Else clause

Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
If Range("A1").Value = "" Then
    Cancel = True
    MsgBox "The 'Save As' function has been disabled."
End If
End Sub

To allow you to save, in the code window press CTRL + G to open the Immediate Window, type

Application.EnableEvents=False

and press Enter.

To re-enable events

Application.EnableEvents=True
 
Upvote 0
Hi,

I need a lil bit more help here...

basically this is what im trying to do...

I want users to have macros enabled and if they dont they should be prompted to do enable them.

To do this I have set up a workbook open event.

secondly, when macros are enabled a user should be unable to save the workbook if a certain cell is left blank.

Now I think Im getting somewhere but the issue I'm having is that when a user is prompted that save has been disabled the work book just closes.

I hope Im making sense. I'd attatch the workbook but not sure how do it.

but here is my code, its all in "Thisworkbook" using excel 2007.

any help/suggestions are much appreciated.

thanks

Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    Call CustomSave(SaveAsUI)
    Cancel = True
End Sub
 
Private Sub Workbook_Open()
'Unhide all worksheets
    Application.ScreenUpdating = False
 
    Call ShowSheets
 
    Application.ScreenUpdating = True
End Sub
 
Private Sub Workbook_BeforeClose(Cancel As Boolean)
'Turn off events to prevent unwanted loops
    Application.EnableEvents = False
 
    'Evaluate if workbook is saved and emulate default propmts
    With ThisWorkbook
        If Not .Saved Then
            Select Case MsgBox("Do you want to save the changes you made to '" & .Name & "'?", _
                vbYesNoCancel + vbExclamation)
                Case Is = vbYes
                    'Call customized save routine
                    Call CustomSave
                Case Is = vbNo
                    'Do not save
                Case Is = vbCancel
                    'Set up procedure to cancel close
                    Cancel = True
            End Select
        End If
 
    'If Cancel was clicked, turn events back on and cancel close,
    'otherwise close the workbook without saving further changes
        If Not Cancel = True Then
            .Saved = True
            Application.EnableEvents = True
            .Close savechanges:=False
        Else
            Application.EnableEvents = True
        End If
    End With
 
End Sub
 
Sub CustomSave(Optional SaveAs As Boolean)
 
    Dim ws As Worksheet, aWs As Worksheet, newFname As String
    Dim ans As String
 
    'Turn off screen flashing
    Application.ScreenUpdating = False
    Set aWs = ActiveSheet
 
    'Hide all sheets
    Call HideSheets
   If Worksheets("BAU_Form").Range("D9").Value = "" Then
     SaveAs = False
    MsgBox ("Save as has been disabled")
   Else
       'Save workbook directly or prompt for saveas filename
        If SaveAs = True Then
            newFname = Application.GetSaveAsFilename( _
                 fileFilter:="Excel Files (*.xls), *.xls")
            If Not newFname = "False" Then ThisWorkbook.SaveAs newFname
        Else
            ThisWorkbook.Save
        End If
    End If
 
    'Restore file to where user was
    Call ShowSheets
    aWs.Activate
 
    'Restore screen updates
    Application.ScreenUpdating = True
 
End Sub
 
Private Sub ShowSheets()
'Show all worksheets except the macro welcome screen
Dim ws As Worksheet
    For Each ws In ThisWorkbook.Worksheets
        If Not ws.Name = "Macros" Then ws.Visible = xlSheetVisible
    Next ws
 
    Worksheets("Macros").Visible = xlSheetHidden
 
End Sub
 
Private Sub HideSheets()
'Side all workshhets except the macros welcome screen
Dim ws As Worksheet
    Worksheets("Macros").Visible = xlSheetVisible
    For Each ws In ThisWorkbook.Worksheets
        If Not ws.Name = "Macros" Then ws.Visible = xlSheetHidden
    Next ws
 
    Worksheets("Macros").Activate
 
End Sub
 
Upvote 0
Hi,

I have used the follwoing code:

Code:
Private Sub Workbook_Open()
CreateSaveMenu
End Sub
Private Sub Workbook_Deactivate()
On Error Resume Next
DeleteSaveMenu
End Sub
Private Sub Workbook_Activate()
CreateSaveMenu
End Sub
Private Sub Workbook_Close()
DeleteSaveMenu
End Sub

I mistakenly put in a module rather than a workbook and now I can't save anything in the usual manner. Even in new files.

Any ideas how to undo this. Im pretty sure im being a bit dopey.

Thanks
Paul
 
Upvote 0

Forum statistics

Threads
1,214,523
Messages
6,120,031
Members
448,940
Latest member
mdusw

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top