Others

Create a VBA Count-Up Timer in PowerPoint

Maira MehtabMaira Mehtab Nov 22, 2026 868 views

Question details

Create a PowerPoint timer that displays the number of days since an incident and can be reset with a button.

Create a VBA Count-Up Timer in PowerPoint
Product
Microsoft PowerPoint
Device & OS
not provided
Scenario
A presentation displays a days-since-incident count that advances at midnight and restarts when an action button is selected.
Observed behavior
The display should show the elapsed calendar days and update automatically while the slide show is running.
Before you start

The VBA example below requires PowerPoint 2010 or later on Windows and a macro-enabled presentation. Enable macros only for files you trust, and decide whether the count should advance at midnight or after each full 24-hour period; this example uses calendar days.

Solution 1Recommended

Build a midnight count-up timer with VBA and action buttons

Use this Windows VBA example to calculate days from a saved incident date and refresh the displayed count during a slide show.

The timer checks the computer's local date once per minute. It counts calendar-day boundaries, so the number advances shortly after midnight rather than exactly 24 hours after the reset.

The example stores the incident date in a presentation tag. It saves the presentation when the timer is first initialized or reset, so the file must be writable.

1
Create the counter shape

Open the presentation in PowerPoint and choose File > Save As to save it as a PowerPoint Macro-Enabled Presentation (.pptm). Insert a text box on the timer slide, then use Home > Select > Selection Pane to rename the text box DaysCounter.

2
Add the VBA code

Press Alt+F11, choose Insert > Module, and paste the following code into the standard module: Option Explicit Private Declare PtrSafe Function SetTimer Lib "user32" (ByVal hWnd As LongPtr, ByVal nIDEvent As LongPtr, ByVal uElapse As Long, ByVal lpTimerFunc As LongPtr) As LongPtr Private Declare PtrSafe Function KillTimer Lib "user32" (ByVal hWnd As LongPtr, ByVal nIDEvent As LongPtr) As Long Private timerId As LongPtr Private timerPresentation As Presentation Public Sub StartCountUp() Set timerPresentation = ActivePresentation If timerPresentation.Tags("INCIDENTDATE") = "" Then timerPresentation.Tags.Add "INCIDENTDATE", Format$(Date, "yyyymmdd") timerPresentation.Save End If If timerId <> 0 Then KillTimer 0, timerId timerId = SetTimer(0, 0, 60000, AddressOf CountUpTick) UpdateCountUp End Sub Public Sub ResetCountUp() Set timerPresentation = ActivePresentation timerPresentation.Tags.Add "INCIDENTDATE", Format$(Date, "yyyymmdd") timerPresentation.Save StartCountUp End Sub Public Sub StopCountUp() If timerId <> 0 Then KillTimer 0, timerId timerId = 0 Set timerPresentation = Nothing End Sub Public Sub CountUpTick(ByVal hWnd As LongPtr, ByVal uMsg As Long, ByVal idEvent As LongPtr, ByVal dwTime As Long) On Error Resume Next UpdateCountUp End Sub Private Sub UpdateCountUp() Dim savedDate As String Dim incidentDate As Date Dim daysElapsed As Long savedDate = timerPresentation.Tags("INCIDENTDATE") incidentDate = DateSerial(CInt(Left$(savedDate, 4)), CInt(Mid$(savedDate, 5, 2)), CInt(Right$(savedDate, 2))) daysElapsed = DateDiff("d", incidentDate, Date) timerPresentation.SlideShowWindow.View.Slide.Shapes("DaysCounter").TextFrame.TextRange.Text = CStr(daysElapsed) End Sub

3
Assign the action buttons

On the timer slide, insert two shapes and label them Start and Reset. Select each shape, choose Insert > Action, select Run macro on the Mouse Click tab, and assign StartCountUp to Start and ResetCountUp to Reset.

4
Test the slide show

Start the slide show, select Start, and check that the DaysCounter text box displays a number. Select Reset to return the count to zero, then test across midnight to confirm that it advances. Start the timer again each time you reopen the presentation.

5
Stop the timer before editing

Exit the slide show, open View > Macros, select StopCountUp, and choose Run before editing the VBA code or closing the presentation.

Build a midnight count-up timer with VBA and action buttons
Timer reliability: The counter updates only while PowerPoint is running and the timer has been started. Windows timer callbacks and VBA depend on PowerPoint remaining responsive; test the presentation in its intended environment and restart it periodically. The counter shape must be present on the currently displayed slide.
Free Microsoft Office alternative

Create and present slides with WPS Presentation

WPS Office is a free, lightweight alternative for creating and presenting slides. Its familiar interface and PowerPoint format support make it easy to move existing presentations into your workflow. It does not fix or replace the Windows PowerPoint VBA timer shown above.

Create and present slide decks in a familiar interfaceOpen and edit Microsoft PowerPoint PPT and PPTX filesUse a free, lightweight office suite for everyday presentation workMove existing slide content into WPS for continued editing
QA img-9

Frequently Asked Questions

Does the counter update exactly 24 hours after a reset?

No. The example uses DateDiff to count calendar days and checks the date once per minute, so it advances shortly after local midnight.

How do I reset the days-since-incident count?

During the slide show, select the Reset action button assigned to ResetCountUp. The macro stores today's date, saves the presentation, and displays zero.

Why does the counter not update after I reopen the file?

The Windows timer does not continue after PowerPoint closes. Start the slide show and select the Start button assigned to StartCountUp each time you reopen the presentation.

Can I use this VBA example on a Mac?

No. This example calls the Windows user32 timer API and is intended for PowerPoint on Windows. A Mac solution would need a different update mechanism.

Why is the counter blank on another slide?

The macro updates a text box named DaysCounter on the currently displayed slide. Add and name that text box on each slide where you want the count to appear.