我使用以下代码进行倒计时,在幻灯片放映模式下,该倒计时将跨越 10 张幻灯片。我将形状放置在 SlideMaster Layout 中。
Set QS = ActivePresentation.Designs(2).SlideMaster.CustomLayouts(2)
Dim Seconds As Integer
Seconds = 30
QS.Shapes("Counter").TextFrame.TextRange = Seconds
For i = 1 To 30
Dim WAIT As Double
WAIT = Timer
While Timer < WAIT + 1
DoEvents
Wend
Seconds = Seconds - 1
QS.Shapes("Counter").TextFrame.TextRange = Seconds
Next i
Run Code Online (Sandbox Code Playgroud)
Dim time As Date
Dim count As Integer
time = Now()
count = 30
time = DateAdd("s", count, time)
Do Until time < Now
DoEvents
With ActivePresentation.Designs(2).SlideMaster.CustomLayouts(2).Shapes("Counter").TextFrame.TextRange
.Text = Format((time - Now()), "hh:mm:ss")
End With
Loop
Run Code Online (Sandbox Code Playgroud)
如果它们没有放置在 SlideMaster Layout 中,这两个代码都可以正常工作。
有没有更好的方法来跨多张幻灯片进行倒计时?
小智 1
有一种更好的方法来显示倒计时Format (Now(), "hh:mm:ss")
要创建倒计时,我们需要两个值:
Dim time As Date
Dim count As Integer
time = Now() 'the current time
count = 30
time = DateAdd("s", count, time) 'the future time after 30 seconds
Run Code Online (Sandbox Code Playgroud)
上面给了我们两个值。
现在,我们可以创建一个循环来更改形状内的文本Counter。
Do Until time < Now() 'We change text until the present time passes the set "future time"
DoEvents
For i = 1 To 10 'Assuming you want the countdown in slides 1 To 10
With ActivePresentation.Slides(i).Shapes("countdown").TextFrame.TextRange
.Text = Format((time - Now()), "hh:mm:ss")
End With
Next i
Loop
Run Code Online (Sandbox Code Playgroud)
您可以使用它来跨多张幻灯片进行倒计时。