Attribute VB_Name = "Modtime"
Public Declare Function MsgWaitForMultipleObjects Lib "user32" (ByVal nCount As Long, pHandles As Long, ByVal fWaitAll As Long, ByVal dwMilliseconds As Long, ByVal dwWakeMask As Long) As Long
Public Sub SafeSleep(ByVal inWaitSeconds As Single)

Const WAIT_OBJECT_0 As Long = 0
Const WAIT_TIMEOUT As Long = &H102

Dim lastTick As Single
Dim timeout As Long
timeout = inWaitSeconds * 10000
lastTick = Timer

Do
    Select Case MsgWaitForMultipleObjects(0, 0, False, timeout, 255)
    Case WAIT_OBJECT_0
        
        DoEvents
        timeout = ((inWaitSeconds) - (Timer - lastTick)) * 10000
        If timeout < 0 Then timeout = 0
    
    Case Else
        Exit Do
    End Select

Loop While True

End Sub
