Control When Events Are Handled

Events are a powerful aspect of Excel programming. They enable you to make your application respond to user actions such as entering data into cells or clicking the print button.

If your application uses events, you will probably also need to be able to control whether or not an event executes its code or not (e.g. to avoid event looping or to enable your code to do things you are preventing your user to do through the user interface).

This article shows a method to gain fine control over which event fires and which does not.

Posted in Uncategorized

2 thoughts on “Control When Events Are Handled

  1. I guess my only question is in reality what’s so bad about having the one global variable instead of one per class module? You admit to using it yourself and I know I do. I know it makes a module slightly less modular and is probably an affront to various syntax style rules but where else does it impact? I’m sure you’re right it’s bad, just can’t see why myself.

  2. Well, I guess it is mostly just about keeping stuff that belongs together in the same place, so indeed it is about mudolarity.

    I also like the idea to get the fact whether or not an event is enabled as a property of the class:

    MyObjFromClass.NoEvents=True

    This also means that when you apply it to a class, you will be disabling just for one instance of that class and not for all instances (which happens if you use a global variable), which gives you more control.


Posting code? Use <pre> tags for VBA and <code> tags for inline.

Leave a Reply

Your email address will not be published.