为什么倒数计时器放置在 SlideMaster 中时会冻结? [英] Why does a countdown timer freeze when placed in SlideMaster?

查看:36
本文介绍了为什么倒数计时器放置在 SlideMaster 中时会冻结?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下代码进行倒计时,在幻灯片放映模式下,该倒计时将跨越 10 张幻灯片.我将形状放置在 SlideMaster 布局中.

I used the following code to have a Countdown which would span over 10 slides whilst in slideshow mode. I placed the shapes in a 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

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

如果两个代码没有放在 SlideMaster Layout 中,它们都可以正常工作.

Both the codes work properly if they are not placed in SlideMaster Layout.

是否有更好的方法来跨多张幻灯片进行倒计时?

Are there any better means to have a countdown that spans across multiple slides?

推荐答案

使用 Format (Now(), "hh:mm:ss") 有更好的方式来显示倒计时

There is a better way to show a countdown by using the Format (Now(), "hh:mm:ss")

要创建倒计时,我们需要两个值:

To create a countdown we need two values:

  1. 当前时间
  2. 倒计时结束的未来时间

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

上面给了我们两个值.

现在,我们可以创建一个循环来更改 Counter 形状内的文本.

Now, we can make a loop to change the text inside the Counter shape.

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

您可以使用它对多张幻灯片进行倒计时.

You can use this to have a countdown across multiples slides.

这篇关于为什么倒数计时器放置在 SlideMaster 中时会冻结?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆