+ Reply to Thread
Results 1 to 7 of 7

Prevent Saving If No Checkboxes Are Selected

  1. #1
    Registered User
    Join Date
    03-06-2020
    Location
    Sacramento, California
    MS-Off Ver
    MS Office 2013
    Posts
    4

    Prevent Saving If No Checkboxes Are Selected

    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.

    Please Login or Register  to view this content.
    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

  2. #2
    Valued Forum Contributor
    Join Date
    11-26-2012
    Location
    Sydney
    MS-Off Ver
    2010
    Posts
    422

    Re: Prevent Saving If No Checkboxes Are Selected

    Do you get the MsgBox when you try to save? I don't know if this will make any difference, but I think you should be using Me.Sheets instead of Application.Sheets.

    It will be easier to help if you upload the workbook.

  3. #3
    Registered User
    Join Date
    03-06-2020
    Location
    Sacramento, California
    MS-Off Ver
    MS Office 2013
    Posts
    4

    Re: Prevent Saving If No Checkboxes Are Selected

    No, I do not get the message box when I try to save. Unfortunately, due to the nature of the workbook, I can't upload it. I'm guessing the way I'm referencing the sheet is the issue, but I've used that reference before with no issues so it's a bit weird. I'll try using the Me.Sheets and let you know if it works.

  4. #4
    Registered User
    Join Date
    03-06-2020
    Location
    Sacramento, California
    MS-Off Ver
    MS Office 2013
    Posts
    4

    Re: Prevent Saving If No Checkboxes Are Selected

    I tested it using the Me.Sheets, but it didn't work.

  5. #5
    Valued Forum Contributor
    Join Date
    11-26-2012
    Location
    Sydney
    MS-Off Ver
    2010
    Posts
    422

    Re: Prevent Saving If No Checkboxes Are Selected

    Do you disable events somewhere in your code? If events are disabled, the sub will never get called. Try adding a MsgBox at the top of your code to test. (Also, I've added and End If at the end - I don't understand how your code is running at all with that missing).

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    03-06-2020
    Location
    Sacramento, California
    MS-Off Ver
    MS Office 2013
    Posts
    4

    Re: Prevent Saving If No Checkboxes Are Selected

    I have other events running that don't interfere with this event so that shouldn't be an issue. I also have an "End If," but I guess I didn't bring it over. There must be something wrong with the code itself. Excel doesn't even throw me an error so I'm not sure what's going on.

  7. #7
    Valued Forum Contributor
    Join Date
    11-26-2012
    Location
    Sydney
    MS-Off Ver
    2010
    Posts
    422

    Re: Prevent Saving If No Checkboxes Are Selected

    Without seeing the workbook, it is hard to offer much assistance, but I do have a couple suggestions.

    1. I think you should be using And rather than Or - the only time the code should be executed is if all checkboxes are unticked, but your logic will have it run if any are unticked.
    2. 0 does not mean unticked - try xlOff instead.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. VBA to prevent saving
    By Tcowap in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-22-2015, 02:56 PM
  2. ActiveX checkboxes move after saving and re-opening file
    By Angelammarten in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-29-2015, 02:41 PM
  3. prevent a sheet from saving
    By CappyLarou in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-27-2011, 09:08 AM
  4. Prevent saving
    By LydiasDad in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-11-2011, 02:40 PM
  5. No less then 3 of Four checkboxes selected
    By CParnell in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-03-2008, 06:13 PM
  6. Prevent Checkbox2 being Selected if Checkbox1 is Selected
    By johnnywinter in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-16-2007, 02:01 AM
  7. prevent saving a worksheet
    By looking4help in forum Excel General
    Replies: 2
    Last Post: 03-17-2005, 07:06 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1