+ Reply to Thread
Results 1 to 9 of 9

Clearing form control checkboxes automatically on opening workbook

  1. #1
    Registered User
    Join Date
    02-12-2009
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2007
    Posts
    32

    Clearing form control checkboxes automatically on opening workbook

    Hi to all,

    I'm developing a workbook containing 121 sheets. Sheet 1 is effectively an index, and uses 120 form control checkboxes to unhide and display the selected sheets individually.

    The code I'm using for each checkbox is below and is in a module.

    Please Login or Register  to view this content.
    The code will hide the sheet again if the box is unchecked, and this is what should be done by the operator before closing the workbook. Surprise - that doesn't always happen.

    I've worked out that adding the following code (for each sheet) to the workbook module does the job of hiding the sheets on opening.

    Please Login or Register  to view this content.
    I'm left with two problems and any help will be greatly appreciated.

    Code to hide all the sheets on opening the workbook (except sheet 1), rather than repeating the line above 120 times?

    Code to uncheck (on opening the workbook) any checkboxes which had not been unchecked when the worbook was last saved/closed? My preference is to do this automatically rather than with a macro requiring some user input.

    I'm very new to vba (still at the guess-copy-try stage) so apologies if the questions have simple or obvious answers.

    Thanks in advance.

    Cheers.
    Last edited by glenin; 05-08-2009 at 08:20 PM.

  2. #2
    Valued Forum Contributor Richard Schollar's Avatar
    Join Date
    05-23-2006
    Location
    Hampshire UK
    MS-Off Ver
    Excel 2002
    Posts
    1,264

    Re: Clearing form control checkboxes automatically on opening workbook

    Open up the VBE, open up the ThisWorkbook module of your workbook and insert the following code:

    Please Login or Register  to view this content.
    Richard Schollar
    Microsoft MVP - Excel

  3. #3
    Registered User
    Join Date
    02-12-2009
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2007
    Posts
    32

    Re: Clearing form control checkboxes automatically on opening workbook

    Thanks Richard,

    The first part works like a treat - all open sheets other than sheet 1 are hidden on opening.

    I'm having trouble with the check box clearing though. My sheet 1 is named Cumulative, and I substituted "Sheet1" in your code with "Cumulative", but I keep getting the following error message on opening

    Run Time Error '1004'
    Unable to set the Value property of the Checkboxes class

    What am I doing wrong?

    Thanks again.

  4. #4
    Valued Forum Contributor Richard Schollar's Avatar
    Join Date
    05-23-2006
    Location
    Hampshire UK
    MS-Off Ver
    Excel 2002
    Posts
    1,264

    Re: Clearing form control checkboxes automatically on opening workbook

    Are the checkboxes created from the Controls Toolbox or from the Forms Toolbar?

    Richard

  5. #5
    Registered User
    Join Date
    02-12-2009
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2007
    Posts
    32

    Re: Clearing form control checkboxes automatically on opening workbook

    I'm using Excel 2007.

    Checkboxes are created from Develop tab> Insert> Form Controls > Check Box (Form Control).

  6. #6
    Registered User
    Join Date
    02-12-2009
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2007
    Posts
    32

    Re: Clearing form control checkboxes automatically on opening workbook

    Correction to prior post
    Developer tab> Controls group> Insert> Form Controls> Check Box (Form Control)

  7. #7
    Valued Forum Contributor Richard Schollar's Avatar
    Join Date
    05-23-2006
    Location
    Hampshire UK
    MS-Off Ver
    Excel 2002
    Posts
    1,264

    Re: Clearing form control checkboxes automatically on opening workbook

    Hmm, I'm not sure why that's giving an error (you definitely have Forms controls from your description (which are the right ones to use)). It works fine for me (in 2007 and 2002).

    What about with the Cumulative sheet active you open up the VBE (Alt+F11), then open up the Immediate Window (Ctrl+G) and type into that the following and press enter. Does it error out in this case?

    Please Login or Register  to view this content.
    Richard

  8. #8
    Registered User
    Join Date
    02-12-2009
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2007
    Posts
    32

    Re: Clearing form control checkboxes automatically on opening workbook

    Richard

    Tried that - same error message on hitting return.

    Just in case I had some sort of conflict beyond my limited vba understanding I also tried your original code as a stand-alone ie. I removed all other vba code from both the Cumulative sheet window and the ThisWorkbook window.

    Still the same error message.

    Glenn

  9. #9
    Registered User
    Join Date
    02-12-2009
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2007
    Posts
    32

    Re: Clearing form control checkboxes automatically on opening workbook

    Richard,

    Got it!

    I replaced the
    Sheets("Sheet1").CheckBoxes.Value = 0
    line with the following and everything now seems to be just peachy.

    Please Login or Register  to view this content.
    Thanks again for setting me on the right path - you've helped my (limited) vba knowledge more than you know.

    Cheers

    Glenn

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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