Timing Delays in VBA

后端 未结 12 2240
陌清茗
陌清茗 2020-11-28 13:48

I would like a 1 second delay in my code. Below is the code I am trying to make this delay. I think it polls the date and time off the operating system and waits until the

12条回答
  •  时光取名叫无心
    2020-11-28 14:24

    With Due credits and thanks to Steve Mallroy.

    I had midnight issues in Word and the below code worked for me

    Public Function Pause(NumberOfSeconds As Variant)
     '   On Error GoTo Error_GoTo
    
        Dim PauseTime, Start
        Dim objWord As Word.Document
    
        'PauseTime = 10 ' Set duration in seconds
        PauseTime = NumberOfSeconds
        Start = Timer ' Set start time.
    
        If Start + PauseTime > 86399 Then 'playing safe hence 86399
    
        Start = 0
    
        Do While Timer > 1
            DoEvents ' Yield to other processes.
        Loop
    
        End If
    
        Do While Timer < Start + PauseTime
            DoEvents ' Yield to other processes.
        Loop
    
    End Function
    

提交回复
热议问题