1

I am trying to create a counter that increments 1 every second in VBA of Powerpoint presentation. This is what I have come up so far.

Sub countup()
    Dim index As Integer

    index = 0
    Do Until index > 100
    index = index + 1

    DoEvents
        With ActivePresentation.Slides(1).Shapes(3).TextFrame.TextRange
        .Text = index
        End With

    Loop
End Sub

This code increments 1 until 101 but it does not increment 1 every second. This is in VBA Powerpoint so I cannot put a timer control. Hope you could help. Thank you.

1 Answer 1

3

This is a possible solution:

Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Public Sub TestMe2()

    Dim index As Long
    index = 0

    Do Until index > 10
        index = index + 1
        Debug.Print index
        Sleep (1000)
    Loop

End Sub

Without adding .Net features, its possible to do it like this:

Public Sub TestMe()

    Dim lngIndex            As Long
    Dim sngSec              As Single '9GAG
    Dim sngAddSec           As Single

    sngAddSec = 1

    Do Until lngIndex > 4
        lngIndex = lngIndex + 1
        sngSec = Timer + sngAddSec
        Debug.Print lngIndex
        While Timer < sngSec: Wend
    Loop

End Sub
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.