I know I'm doing something wrong here. I'm trying to use the sleep function to delay my code, but I get "Sub or Function not defined" error. Any tips?
+3
A:
VBA does not have a Sleep
function.
You can import it from Kernel32.dll like this:
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Note that this will freeze the application.
You can also call DoEvents
in a While
loop, which won't freeze the application.
SLaks
2010-04-29 13:35:34
Where in the code do I put that declaration? I've tried sticking it in outside and inside of the sub I'm working on, but get errors both times.
Soo
2010-04-29 13:39:29
What error? Try putting it in a Module.
SLaks
2010-04-29 13:40:52
Oh, oops, I was trying to put it into an excel object (silly me). I put it in a module and now it works. Thanks so much! I checked your answer.
Soo
2010-04-29 13:45:35
+3
A:
You can also pause the current macro context with Application.Wait T
which won't block the whole process.
Alex K.
2010-04-29 15:42:21