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

antman2988

New Member
Joined
Jun 28, 2018
Messages
26
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

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,547
Office Version
  1. 365
Platform
  1. Windows
Change to 0 to -4146
VBA Code:
Application.Sheets("Assign_FI$Cal_Project_Code").Shapes("Check Box 179").ControlFormat.Value = -4146 Or...
 

Watch MrExcel Video

Forum statistics

Threads
1,129,549
Messages
5,636,929
Members
416,953
Latest member
prakashkumar

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
Top