DoEvents

almagg

Well-known Member
Joined
Aug 21, 2002
Messages
705
i have some code from the forum here which creates a Progress Bar - nice.

there is a DoEvents line, but the program works without it.
i did an online search but did not find any decent explanation i.e., that i could understand :)

so what does the DoEvents do?

thanks.
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
my theroy

its not needed for excel because windows doesn't do 1 thing at a time anymore and windows can handle it. although with access it probably still is needed
 
Upvote 0
almagg - you have around 5 more messages which are copies of this.
It is pretty easy to do when the board is slow.
Would you please delete them.
----------------------------------------------------------------------
DoEvents stops the macro running, allows Windows to process any outstanding events, and then continues the macro.

An example of this is when using Sendkeys to send keyboard commands - let's say to manipulate menus in an application outside Excel. The problem is that Windows is politely waiting for the macro to end. Also the code runs so fast that it does not allow time for things to happen on screen before it processes its next command.

In this case, apart from adding "Wait" statements to actually stop the macro running for a second or so, we have to put a DoEvents line to make sure that the "keyboard entries" are processed.

Another use of DoEvents might be when downloading data from a server, or printing. There do not seem to be any firm rules here - sometimes it is needed, sometimes not. As you have seen, it does not hurt to put it in just in case.
 
Upvote 0

Forum statistics

Threads
1,214,584
Messages
6,120,385
Members
448,956
Latest member
JPav

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top