Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

New to VB in Excel Need to pause Macro 1

Status
Not open for further replies.

Barneye

MIS
Mar 5, 2002
68
US
Hello!


I have a macro in Excel that I wrote. I need it pause to 10 seconds before it executes the next set of code. I am using

Code:
Application.Wait Now + TimeValue("00:00:10")

This works but seems to freeze the entire application. I have ODBC updates running in the background that need to run while the macro is paused.

Is there an "easy" way to accomplish this?

Thanks!
 
Hi, try adding this to the end of your code

Code:
Private Sub WaitRoutine(NoSeconds)
Dim PauseTime As Long
Dim Start As Long
Dim Finish As Long

    PauseTime = NoSeconds   ' Set duration.
    Start = Timer   ' Set start time.
    Do While Timer < Start + PauseTime
        DoEvents    ' Yield to other processes.
    Loop
    Finish = Timer  ' Set end time.
End Sub

Then at the point you want to pause, insert the line
Code:
WaitRoutine(10) 'e.g. wait for 10 seconds
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top