Countdown timer on the userform.

asyamonique

Well-known Member
Joined
Jan 29, 2008
Messages
1,280
Office Version
  1. 2013
Platform
  1. Windows
Good Day,
Is it possible to add in my userform top corner one countdown timer with three buttons, one will start(down from two minutes) other is stop and another will be reset button?

Many Thanks
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
VBA Code:
Private Declare Function SetTimer Lib "User32" (ByVal hWnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Private Declare Function KillTimer Lib "User32" (ByVal hWnd As Long, ByVal nIDEvent As Long) As Long

Option Explicit

Dim TimerID As Long
Private Sub Chrono()
Dim T As Double
    T = TimeValue(UserForm3.LblTemps.Caption) - TimeSerial(0, 0, 1)
    UserForm3.LblTemps.Caption = Format(T, "hh:mm:ss")
    If T = 0 Then TimerOff

'///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
'As an alternative you could try making a call to a separate Sub with the sound command/s, instead of placing the code here.
 
    If UserForm3.LblTemps.Caption = "00:59:55" Then '<--- set the time for sound here
        Beep  '<-- place your command here for sound
    End If
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

End Sub
Sub TimerOff()
    KillTimer 0, TimerID
End Sub

Sub TimerOn(Interval As Long)
    TimerID = SetTimer(0, 0, Interval, AddressOf Chrono)
End Sub


Download File :
Internxt Drive – Private & Secure Cloud Storage
 
Upvote 0
VBA Code:
Private Declare Function SetTimer Lib "User32" (ByVal hWnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Private Declare Function KillTimer Lib "User32" (ByVal hWnd As Long, ByVal nIDEvent As Long) As Long

Option Explicit

Dim TimerID As Long
Private Sub Chrono()
Dim T As Double
    T = TimeValue(UserForm3.LblTemps.Caption) - TimeSerial(0, 0, 1)
    UserForm3.LblTemps.Caption = Format(T, "hh:mm:ss")
    If T = 0 Then TimerOff

'///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
'As an alternative you could try making a call to a separate Sub with the sound command/s, instead of placing the code here.
 
    If UserForm3.LblTemps.Caption = "00:59:55" Then '<--- set the time for sound here
        Beep  '<-- place your command here for sound
    End If
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

End Sub
Sub TimerOff()
    KillTimer 0, TimerID
End Sub

Sub TimerOn(Interval As Long)
    TimerID = SetTimer(0, 0, Interval, AddressOf Chrono)
End Sub


Download File :
Internxt Drive – Private & Secure Cloud Storage
Hello,
Thx for the quick reply. :)
Having below error.
VBA Code:
Private Declare [COLOR=rgb(235, 107, 86)]Function [/COLOR]SetTimer Lib "User32" (ByVal hWnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
 
Upvote 0
1. There should also be a line or lines of code that are highlighted in yellow. Which line / lines were they ?

2. Are you running a 64 bit copy of Windows ? Or is it a 32 bit ?
 
Upvote 0
1. There should also be a line or lines of code that are highlighted in yellow. Which line / lines were they ?

2. Are you running a 64 bit copy of Windows ? Or is it a 32 bit ?
I've simply downloaded your file and it did not run.
Using 64bit.
Tq
 
Upvote 0
Ok. I too am running Win 10 / 64 bit. However, the project runs fine here.

????
 
Upvote 0
Hello Again,
Found that below code and so far it worked in my project.
Only one think i counldn't fix when its stop actually I wanted make it disappear without click userform as;
VBA Code:
lblCountdown = ("")
Also when its running sometimes the screen blinking :))
Tq.




VBA Code:
Private Sub lblCountdown_Click()

nTime = 0

lblCountdown = ("")

End Sub






VBA Code:
Private Sub UserForm_DblClick(ByVal Cancel As MSForms.ReturnBoolean)

nTime = nCount
Call RunTimer

End Sub




VBA Code:
Public Const nCount As Long = 120 ' secs
Public nTime As Double


Public Sub RunTimer()


Application.ScreenUpdating = False


If nTime > 1 Then

nTime = nTime - 1
list.lblCountdown.Caption = Format(TimeSerial(0, 0, nTime), "hh:mm:ss")
Application.OnTime Now + TimeSerial(0, 0, 1), "RunTimer"
Else

End If

Application.ScreenUpdating = True


End Sub
 
Upvote 0

Forum statistics

Threads
1,215,102
Messages
6,123,099
Members
449,096
Latest member
provoking

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top