+ Reply to Thread
Results 1 to 8 of 8

Difference between manual "click" of activeX checkbox and coded "click"

  1. #1
    Forum Contributor
    Join Date
    12-20-2011
    Location
    United States, Ohio
    MS-Off Ver
    Excel 2010
    Posts
    295

    Question Difference between manual "click" of activeX checkbox and coded "click"

    Is there a way to trick excel in knowing the different between an actual user manual click of a check box and when its changed programmatically?

    There are many many instances in my code where I change the value of other checkboxes located in other sheets and I have events that run when those checkboxes are clicked.

    But there are times when I dont want those events to run when the user manuals clicks the checkbox and times when I do.


    For example, I would like to have happen that when checkbox5 is MANUALLY clicked by the user, that a certain event runs, but if the value of checkbox5 is changed from other points in the code (programmatically) - I do not want that event to run.

    Is this possible?

  2. #2
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Difference between manual "click" of activeX checkbox and coded "click"

    Use a Boolean variable:
    Please Login or Register  to view this content.
    then when your code needs to set the values without triggering the events, just make blnSkipEvents True, do your stuff, then make it False again.
    Good luck.

  3. #3
    Forum Contributor
    Join Date
    12-20-2011
    Location
    United States, Ohio
    MS-Off Ver
    Excel 2010
    Posts
    295

    Re: Difference between manual "click" of activeX checkbox and coded "click"

    OnErrorGoTo0 - thank you so much for your reply. Sorry for my confusion but I am not quite sure I understand your recommendation. What is the value of blnSkipEvents? Your If statment isnt comparing it to True or false.

    To further example what I am looking for:
    I have (2) sections on Sheet 1 and both sections have checkboxes. Section 1 has (4) checkboxes (1-4) and Section (2) has (19) Checkboxes (5-23).

    Currently if #1,2, or 4 checkbox in section 1 are clicked (either manually or using code) - I have numerous events trigger and certain checkboxes in section 2 change automatically (mainly #5-9).
    I would like that if 5-9 is changed by coded (such as the clicking of 1,2,&4) - then the events are triggerd as nornal. BUT if 5-9 are changed manually to not do "those events" but to do something else.

    I would like to write code for each click of checkboc 5-19 - I just dont want the clicking of 1,2,&4 to trigger those events.

    I am sure your recommendation probably does that as you always seem to be able to help me out - but I just dont understand it.

  4. #4
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Difference between manual "click" of activeX checkbox and coded "click"

    Quote Originally Posted by clemsoncooz View Post
    Your If statement isnt comparing it to True or false.
    There is no need to. An If statement evaluates an expression as either True or False. Since a boolean already is True or False, there is no need to compare it. For example:
    Please Login or Register  to view this content.
    would evaluate to either:
    Please Login or Register  to view this content.
    or
    Please Login or Register  to view this content.
    depending on whether x = 0 or not.
    With a boolean, the comparison to True (or False) is pointless as it converts from:
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    and ultimately to
    Please Login or Register  to view this content.
    which is the same as just
    Please Login or Register  to view this content.

  5. #5
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Difference between manual "click" of activeX checkbox and coded "click"

    To address your other point, if you don't want checkboxes to trigger code when clicked manually, don't assign any code to them. Simply run additional code when setting their values in your code.

  6. #6
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Difference between manual "click" of activeX checkbox and coded "click"

    I use an activeX-property .Tag to prevent executing certain code in eventprocedures:

    Please Login or Register  to view this content.
    the active-X control contains:

    Please Login or Register  to view this content.
    Last edited by snb; 02-23-2012 at 09:41 AM.



  7. #7
    Forum Contributor
    Join Date
    12-20-2011
    Location
    United States, Ohio
    MS-Off Ver
    Excel 2010
    Posts
    295

    Re: Difference between manual "click" of activeX checkbox and coded "click"

    Okay - I really appreicate your willingness to help on this matter so thank you. I still havent figured it out. I have uploaded a sample sheet to further explain my problem. I think I have captured it correctly (I hope).
    Current code:
    Please Login or Register  to view this content.
    Desired:
    When CheckBox 2 is changed via code or manual ,to true then 3 & 4 are always true.

    When 3 or 4 are MANUALLY "changed" to EITHER TRUE or FALSE then 1 is true and 2 is false - BUT currently when 3&4 are changed from checkbox2 event, those events of making 1 true cannot happen. Only when 3&4 are manually clicked is 1 = True.

    When 1 is changed via code or manual, to true then 2 is always false.


    The problem lies within this:
    Currently, when 2 is changed via code to True, 3 & 4 change to true which is correct. BUT that then triggers 3 & 4 event changes which changes 1 to true, which changes 2 back to false which negates the first change of 2 to true.
    Attached Files Attached Files

  8. #8
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Difference between manual "click" of activeX checkbox and coded "click"

    Please Login or Register  to view this content.

+ 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