Hello, I have the following code to start a timer in a userform. All is working except for commandbutton1, build in to stop the timer to execute the closing of the sheet. Is there a way to stop, exit the do while loop by pressing commandbutton1 ?

 Private Sub UserForm_Activate()
 Dim iDuration As Integer
 Dim StartTime As Variant
 Cancel = False
  iDuration = 20
    Time = iDuration
     StartTime = Timer
     Do While Timer - StartTime < iDuration
        Time = iDuration - Round((Timer - StartTime) * 1, 0)
        DoEvents
        Loop
Unload Me
Application.DisplayAlerts = False
ActiveWorkbook.Close savechanges:=False
Application.DisplayAlerts = True
End Sub

Private Sub CommandButton1_Click()
 Cancel = True
 Call StopTimer
 Call SetTimer
 Unload Me
End Sub