tags:

views:

167

answers:

2

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
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
What error? Try putting it in a Module.
SLaks
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
+3  A: 

You can also pause the current macro context with Application.Wait T which won't block the whole process.

Alex K.