Global dTime, bFlag1, bCD
Sub Start()
Stoppen
If bFlag1 Then
dTime = Now + TimeSerial(0, 0, 15) 'now 15 secondes, later 15 minutes !!!
Application.OnTime dTime, "Start", , 1
bCD = False
With UserForm1.TextBox2
.Text = "testing inactivity during 15 minutes until " & Format(dTime, "hh:mm:ss")
.BackColor = RGB(0, 255, 0)
End With
Else
If bCD Then 'was busy counting down and is now done
UserForm1.Hide
MsgBox "countdown terminated at " & Format(Now, "hh:mm:ss")
Else
dTime = Now + TimeSerial(0, 0, 2) 'now 2 seconds, later 2 minutes
Application.OnTime dTime, "Start", , 1
With UserForm1.TextBox2 'normally until then Textbox2 isn't visible
.Visible = True
.Text = "countdown during 2 minutes until " & Format(dTime, "hh:mm:ss")
.BackColor = RGB(255, 255, 0)
End With
bCD = True 'flag counting down
End If
End If
End Sub
Sub Stoppen()
On Error Resume Next
Application.OnTime dTime, "Start", , 0
Application.StatusBar = ""
End Sub
Sub UF1_Show()
UserForm1.Show
End Sub