Use Before Save Event to Prevent Saving If No Checkboxes Are Selected

antman2988

Board Regular
Joined
Jun 28, 2018
Messages
78
Hello!

I am attempting to use the BeforeSave event to check whether any of the checkboxes are selected before allowing the user to save the workbook. Please see my code below.

VBA Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    MsgBox "Entered Sub Workbook_BeforeSave"

    If Application.Sheets("Assign_FI$Cal_Project_Code").Shapes("Check Box 179").ControlFormat.Value = 0 Or Application.Sheets("Assign_FI$Cal_Project_Code").Shapes("Check Box 180").ControlFormat.Value = 0 Or Application.Sheets("Assign_FI$Cal_Project_Code").Shapes("Check Box 181").ControlFormat.Value = 0 Or Application.Sheets("Assign_FI$Cal_Project_Code").Shapes("Check Box 182").ControlFormat.Value = 0 Or Application.Sheets("Assign_FI$Cal_Project_Code").Shapes("Check Box 183").ControlFormat.Value = 0 Or Application.Sheets("Assign_FI$Cal_Project_Code").Shapes("Check Box 187").ControlFormat.Value = 0 Or Application.Sheets("Assign_FI$Cal_Project_Code").Shapes("Check Box 185").ControlFormat.Value = 0 Or Application.Sheets("Assign_FI$Cal_Project_Code").Shapes("Check Box 186").ControlFormat.Value = 0 Then
        Cancel = True
        MsgBox "Save cancelled. Please choose an option in Section 10."
    End If
End Sub

I'm still able to save the workbook even when none of the checkboxes are selected. What is the issue with my code?

Any help is appreciated. Thanks!

-Anthony
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Change to 0 to -4146
VBA Code:
Application.Sheets("Assign_FI$Cal_Project_Code").Shapes("Check Box 179").ControlFormat.Value = -4146 Or...
 
Upvote 0

Forum statistics

Threads
1,224,816
Messages
6,181,143
Members
453,021
Latest member
Justyna P

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