Thread: DoEvents
View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
NickHK NickHK is offline
external usenet poster
 
Posts: 4,391
Default DoEvents

Arne,
According to Help, DoEvents "Yields execution so that the operating system
can process other events.". But read the entry for more info.
So unless your loop requires other events to have been processed in order to
function correct, DoEvents may not be what you are looking for and the error
lies in your code.

Not that I've had cause to use it, but GetQueueStatus is used

<From API-Guide , http://www.allapi.net/
The GetQueueStatus function indicates the type of messages found in the
calling thread's message queue.

Private Const QS_HOTKEY = &H80
Private Const QS_KEY = &H1
Private Const QS_MOUSEBUTTON = &H4
Private Const QS_MOUSEMOVE = &H2
Private Const QS_PAINT = &H20
Private Const QS_POSTMESSAGE = &H8
Private Const QS_SENDMESSAGE = &H40
Private Const QS_TIMER = &H10
Private Const QS_ALLPOSTMESSAGE = &H100
Private Const QS_MOUSE = (QS_MOUSEMOVE Or QS_MOUSEBUTTON)
Private Const QS_INPUT = (QS_MOUSE Or QS_KEY)
Private Const QS_ALLEVENTS = (QS_INPUT Or QS_POSTMESSAGE Or QS_TIMER Or
QS_PAINT Or QS_HOTKEY)
Private Const QS_ALLINPUT = (QS_SENDMESSAGE Or QS_PAINT Or QS_TIMER Or
QS_POSTMESSAGE Or QS_MOUSEBUTTON Or QS_MOUSEMOVE Or QS_HOTKEY Or QS_KEY)

Private Declare Function GetQueueStatus Lib "user32" (ByVal fuFlags As Long)
As Long
Dim bCancel As Boolean

Private Sub Command1_Click()
'initialize this boolean to 'false'
bCancel = False
'start the loop
Do
'check whether there are mouse-button or keyboard messages
'in the message queue. If there are, call DoEvents
If GetQueueStatus(QS_ALLINPUT) Then DoEvents
Loop Until bCancel = True
MsgBox "After loop..."
End Sub
</From API-Guide , http://www.allapi.net/

If that would prove useful knowledge is another question.

NickHK

"Arne Hegefors" wrote in message
...
Hi! I have a macro that keeps hanging. The macro is basically a very long
loop so I am not surprised. I am told that you can use something called
DoEvents in combo with GetQueueStatus API function. However I have no idea
how to use that stuff and nothing comes up in the vba help. If anyone can
quickly describe how to use or knows a good webpage I would be very

grateful.
I have tried to goole it but without any realy success. Many thanks in
advance!