• 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...

  • 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?

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
 
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 …
 
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.
 
Back
Top