我正在做一个项目,我们希望在学生完成项目时在幻灯片上显示倒数计时器。
我在网上找到了多个示例,但是在尝试根据我们的目的调整它们时,我无法让代码按预期运行。
在我的测试中,我在代码中添加了断点以及 debug.prints 来尝试查看它是否正在执行代码,以便我可以单步执行以查看是否存在任何逻辑错误。但是,当我播放幻灯片时,虽然它似乎没有遇到断点,但它确实执行了第一个更新行——ActivePresentation.Slides(1).Shapes("MainTitle").TextFrame.TextRange.Text = "Got To " & Now
我只是不知道如何让它正确倒计时。
您的想法和指导将不胜感激。
Public Sub BAR01_Countdown()
ActivePresentation.Slides(1).Shapes("MainTitle").TextFrame.TextRange.Text = "Got To " & Now
Dim CountTimeEnd As Date
Dim myHours As Integer
Dim myMinutes As Integer
Dim mySeconds As Integer
Dim dispH As Integer
Dim dispM As Integer
Dim dispS As Integer
Dim dispTime As String
Dim secondsRemain As Integer
CountTimeEnd = Now()
myHours = 0
myMinutes = 5
mySeconds = 0
CountTimeEnd = DateAdd("h", myHours, CountTimeEnd)
CountTimeEnd = DateAdd("n", myMinutes, CountTimeEnd)
CountTimeEnd = DateAdd("s", mySeconds, CountTimeEnd)
Do Until CountTimeEnd < Now()
secondsRemain = (DateDiff("s", CountTimeEnd, Now))
dispH = Round((secondsRemain) / (60 * 60), 0)
dispM = Round(((secondsRemain) - (dispH * 60 * 60)) / 60, 0)
dispS = (secondsRemain) - (dispH * 60 * 60) - (dispM * 60)
If dispH > 0 Then
dispTime = Format(dispH, "00") & " : " & Format(dispM, "00") & " . " & Format(dispS, "00")
ElseIf dispH < 0 And dispM > 0 Then
dispTime = Format(dispM, "00") & " . " & Format(dispS, "00")
Else
dispTime = Format(dispS, "00") & " seconds"
End If
ActivePresentation.Slides(1).Shapes("MainTitle").TextFrame.TextRange.Text = dispTime
DoEvents
Loop
End Sub
Sub OnSlideShowPageChange()
BAR01_Countdown
End Sub