Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
'This code goes in the ThisWorkbook code pane
Sub Auto_Open()
TimeToChristmas
End Sub
Sub Auto_Close()
StopTimer
End Sub
'This code goes in a regular module sheet
Public RunTime As Double
Sub TimeToChristmas()
Static lngYear As Long, months As Long, days As Long
Dim hours As Long, minutes As Long, seconds As Long
Static xmas As Double
Dim str As String
If lngYear = 0 Then
lngYear = Year(Date)
xmas = DateSerial(lngYear, 12, 25)
If xmas < Date Then xmas = DateSerial(lngYear + 1, 12, 25)
months = DateDiff("m", Date, xmas)
days = Int(xmas - DateSerial(lngYear, Month(Date) + months, Day(Date))) - 1
End If
hours = Int(24 * (1 - Time))
minutes = Int(59 - Minute(Now))
seconds = Int(60 - Second(Now))
'Build the time string
str = months & " month"
If months > 1 Then str = str & "s"
str = str & ", " & days & " day"
If days > 1 Then str = str & "s"
str = str & ", " & hours & " hour"
If hours > 1 Then str = str & "s"
str = str & ", " & minutes & " minute"
If minutes > 1 Then str = str & "s"
str = str & ", " & seconds & " second"
If seconds > 1 Then str = str & "s"
Sheets(1).Range("A1") = str
RunTime = Now + TimeValue("00:00:01")
Application.OnTime earliesttime:=RunTime, procedure:="TimeToChristmas"
End Sub
Sub StopTimer()
On Error Resume Next
Application.OnTime earliesttime:=RunTime, procedure:="TimeToChrismas", schedule:=False
End Sub
'This code goes in the ThisWorkbook code pane
Sub Auto_Open()
RunXmasTimer = True
TimeToChristmas
End Sub
Sub Auto_Close()
StopTimer
End Sub
'This code goes in a regular module sheet
Public RunTime As Double
Public RunXmasTimer As Boolean
Sub TimeToChristmas()
Static lngYear As Long, months As Long, days As Long
Dim hours As Long, minutes As Long, seconds As Long
Static xmas As Double
Dim str As String
If lngYear = 0 Then
lngYear = Year(Date)
xmas = DateSerial(lngYear, 12, 25)
If xmas < Date Then xmas = DateSerial(lngYear + 1, 12, 25)
months = DateDiff("m", Date, xmas)
days = Int(xmas - DateSerial(lngYear, Month(Date) + months, Day(Date))) - 1
End If
hours = Int(24 * (1 - Time))
minutes = Int(59 - Minute(Now))
seconds = Int(60 - Second(Now))
'Build the time string
str = months & " month"
If months > 1 Then str = str & "s"
str = str & ", " & days & " day"
If days > 1 Then str = str & "s"
str = str & ", " & hours & " hour"
If hours > 1 Then str = str & "s"
str = str & ", " & minutes & " minute"
If minutes > 1 Then str = str & "s"
str = str & ", " & seconds & " second"
If seconds > 1 Then str = str & "s"
Sheets(1).Range("A1") = str
RunTime = Now + TimeValue("00:00:01")
If RunXmasTimer Then _
Application.OnTime earliesttime:=RunTime, procedure:="TimeToChristmas"
End Sub
Sub StopTimer()
RunXmasTimer = False
End Sub
'This code goes in the ThisWorkbook code pane
Public RunTime As Date
Public RunXmasTimer As Boolean
Sub workbook_open()
RunXmasTimer = True
ThisWorkbook.TimeToChristmas
End Sub
Sub workbook_beforeclose(Cancel As Boolean)
StopTimer
End Sub
Sub TimeToChristmas()
'Puts a countdown timer in cell A1 of the first worksheet in this workbook
Static lngYear As Long, Y As Long, months As Long, days As Long
Dim hours As Long, minutes As Long, seconds As Long
Static xmas As Date, Date1 As Date, temp1 As Date, tempus As Date, tyme As Date
Dim str As String
tyme = Time
If lngYear = 0 Then
Date1 = Date
lngYear = Year(Date1)
xmas = DateSerial(lngYear, 12, 25) + TimeValue("9:00:00")
If xmas < Date1 Then xmas = DateSerial(lngYear + 1, 12, 25)
temp1 = DateSerial(Year(xmas), Month(Date1), Day(Date1))
Y = Year(xmas) - Year(Date1) + (temp1 > xmas)
months = Month(xmas) - Month(Date1) - (12 * (temp1 > xmas))
days = Day(xmas) - Day(Date1)
If days < 0 Then
months = months - 1
days = Day(DateSerial(Year(xmas), Month(xmas), 0)) + days
End If
If xmas - Int(xmas) < tyme Then days = days - 1
End If
tempus = xmas - Int(xmas) - tyme
If tempus < 0 Then tempus = tempus + 1
hours = Int(24 * tempus)
minutes = Int(tempus * 1440 - hours * 60)
seconds = Int(tempus * 86400 - hours * 3600 - minutes * 60)
'Build the time string
If Y > 0 Then str = Y & " year"
If Y > 1 Then str = str & "s"
str = months & " month"
If months > 1 Then str = str & "s"
str = str & ", " & days & " day"
If days > 1 Then str = str & "s"
str = str & ", " & hours & " hour"
If hours > 1 Then str = str & "s"
str = str & ", " & minutes & " minute"
If minutes > 1 Then str = str & "s"
str = str & ", " & seconds & " second"
If seconds > 1 Then str = str & "s"
Sheets(1).Range("A1") = str
RunTime = Now + TimeValue("00:00:01")
If RunXmasTimer Then _
Application.OnTime earliesttime:=RunTime, procedure:="ThisWorkbook.TimeToChristmas"
End Sub
Sub StopTimer()
RunXmasTimer = False
End Sub