为什么倒数计时器放在 Slide Master 中会冻结?
Why does a countdown timer freeze when placed in SlideMaster?
我使用以下代码制作了一个倒计时,该倒计时在幻灯片放映模式下跨越 10 张幻灯片。我将形状放在 SlideMaster 布局中。
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 中,它们都可以正常工作。
有没有更好的方法来实现跨多张幻灯片的倒计时?
我模拟了类似的代码:
Set Shape = Application.ActivePresentation.Designs(1).SlideMaster.CustomLayouts(1).Shapes("Testing")
Shape.TextFrame.TextRange.Text = "Did it work"
如您所见,形状的文本在放映幻灯片时没有改变,但在您离开幻灯片后它确实更新了基础幻灯片母版。但是,我发现通过在这段代码之后包含以下内容,它可以按预期工作:
Shape.Visible = msoTrue
使用 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
上面给了我们两个值。
现在,我们可以创建一个循环来更改 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
您可以使用它在多张幻灯片中进行倒计时。
我使用以下代码制作了一个倒计时,该倒计时在幻灯片放映模式下跨越 10 张幻灯片。我将形状放在 SlideMaster 布局中。
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 中,它们都可以正常工作。
有没有更好的方法来实现跨多张幻灯片的倒计时?
我模拟了类似的代码:
Set Shape = Application.ActivePresentation.Designs(1).SlideMaster.CustomLayouts(1).Shapes("Testing")
Shape.TextFrame.TextRange.Text = "Did it work"
如您所见,形状的文本在放映幻灯片时没有改变,但在您离开幻灯片后它确实更新了基础幻灯片母版。但是,我发现通过在这段代码之后包含以下内容,它可以按预期工作:
Shape.Visible = msoTrue
使用 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
上面给了我们两个值。
现在,我们可以创建一个循环来更改 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
您可以使用它在多张幻灯片中进行倒计时。