1. Welcome to Chandoo.org Forums. Short message for you

    Hi Guest,

    Thanks for joining Chandoo.org forums. We are here to make you awesome in Excel. Before you post your first question, please read this short introduction guide. When posting or responding to questions please remember our values at Chandoo.org are: Humility, Passion, Fun, Awesomeness, Simplicity, Sharing Remember that we have people here for whom English is not there first language and we need to allow for this in our dealings.

    Yours,
    Chandoo
  2. Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  3. When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

What is DoEvents In Excel Vba? How & When to use it in Macro?what is Pros & Cons of It?

Discussion in 'VBA Macros' started by Chirag R Raval, Apr 12, 2018.

  1. Chirag R Raval

    Chirag R Raval Member

    Messages:
    661
    Dear All Experts,

    I am sorry but , Though goggling , Every description about DoEvent , make it more complex to understand, & also , there are nothing mentioned about DoEvent in VBA Inner Help,

    I Can not understand roll of "DoEvents" in Excel VBA.

    What is it really it do?
    What is it's Pros & cons?
    How & When to use it? Or How can we efficiently use it in Excel VBA?
    Where should (Or Must0 not to use it in Excel VBA?

    Hope there are someone there can spread little light of knowledge on it.

    Regards,

    Chirag Raval
  2. chirayu

    chirayu Well-Known Member

    Messages:
    946
  3. Marc L

    Marc L Excel Ninja

    Messages:
    4,258
    Hi !

    DoEvents is explained in VBA inner help whatever the Excel version I use
    (from 2003 to 2013) and you can see on MSDN website …

    It may be needed when interacting with others applications
    or within a loop in order to break it via ESC key in case of infinite one
    or to let do something elsewhere …
  4. Chirag R Raval

    Chirag R Raval Member

    Messages:
    661
  5. shrivallabha

    shrivallabha Excel Ninja

    Messages:
    1,920
    A simpler demo of effect of DoEvents you can learn is in this thread:
    https://chandoo.org/forum/threads/basic-animation-examples-using-excel-vba-and-shapes.31038/

    E.g. refer file say "VBA - Animation - Flames.xlsm".

    Caution: Advisable to close all other Excel files before you give this a try!

    Run the file as it is and you will see the animation work. Now comment out line in code where DoEvents is written.

    Press the animation button again. This time around the screen will freeze as VBA has control over the process and you will not be able to perform actions as you may want to. And you will not be able to see animation as well!

    So at runtime, if you need to access application and need control then DoEvents is required. Hope this gives some idea as to how it can be used in the code. Most of the program / macros I write do not need it.
    Chirag R Raval likes this.
  6. Debaser

    Debaser Active Member

    Messages:
    449
    DoEvents is possibly most often used in Excel as a patch for when VBA doesn't work the way it should. There can be no hard and fast rule for that!
    Chirag R Raval and shrivallabha like this.

Share This Page