Prevent Saving

Excelerr

New Member
Joined
Aug 3, 2018
Messages
5
Hello, I'm wondering if there is a way to not allow saving in the workbook if the user has not changed the answer from a validated list? I have Yes, No, and Provide-Answer in the data validation list and some VBA code that does not allow saving with an empty cell but I couldn't save when it was left empty so I added the Provide-Answer. Saving with macros not enabled was not working.
Is there anything I can add in VBA or within excel that will not allow saving without changing a "Provide-Answer"?
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Hello,

Have you tested in the module ThisWorkbook :

Code:
[B]Private Sub Workbook_BeforeSave (ByVal SaveAsUI As Boolean, Cancel As Boolean)
[/B][COLOR=navy][FONT=Courier New] If SaveAsUI = True Then Cancel = True
[/FONT][/COLOR][B]End Sub
[/B]

Hope this will help
 
Upvote 0
You can do something like this

List the values that are not acceptable in cell C7, separated by a comma - the workbook will not save if the cell value matches any one of them

Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    Dim cel As Range: Set cel = Sheets("Sheet1").Range("C7")
    
        Select Case cel.Value
            Case [COLOR=#ff0000]vbNullString, "disallowed reply", 1[/COLOR]
                GoTo CloseWithoutSave
            Case Else
                Exit Sub
        End Select
        
CloseWithoutSave:
    Cancel = True
    If MsgBox("Close without saving?", vbYesNoCancel, "???") = vbYes Then
        ThisWorkbook.Close False
    Else
        cel.Parent.Activate
        cel.Activate
    End If
End Sub

Goes in ThisWorkbook module
 
Last edited:
Upvote 0
You can do something like this

List the values that are not acceptable in cell C7, separated by a comma - the workbook will not save if the cell value matches any one of them

Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    Dim cel As Range: Set cel = Sheets("Sheet1").Range("C7")
    
        Select Case cel.Value
            Case [COLOR=#ff0000]vbNullString, "disallowed reply", 1[/COLOR]
                GoTo CloseWithoutSave
            Case Else
                Exit Sub
        End Select
        
CloseWithoutSave:
    Cancel = True
    If MsgBox("Close without saving?", vbYesNoCancel, "???") = vbYes Then
        ThisWorkbook.Close False
    Else
        cel.Parent.Activate
        cel.Activate
    End If
End Sub

Goes in ThisWorkbook module

This is helpful, could i replace msgbox where closewithoutsave is; ideally I would like an error message to come up and not allow saving, but not close the workbook either.
 
Upvote 0
Try removing the line that closes the workbook and see if that gives you the functionality you want.
If it does, remove the whole of that IF statement and just leave the 2 lines beginning with cel.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,693
Members
448,979
Latest member
DET4492

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