alt+f11启动,添加模块,里面查看中文设置文本框位置
Sub InsertTextBoxesAndSyncCountdown()
Dim slide As slide
Dim textBox As Shape
Dim slideIndex As Integer
Dim initialText As String
initialText = "60:00" ' 初始倒计时文本
' 遍历每一张幻灯片
For slideIndex = 1 To ActivePresentation.Slides.Count
Set slide = ActivePresentation.Slides(slideIndex)
' 插入文本框
' 在幻灯片上插入文本框
' 第一个参数:文本方向(水平)
' 第二个参数:文本框的左边距(相对于幻灯片左边缘)
' 第三个参数:文本框的顶边距(相对于幻灯片上边缘)
' 第四个参数:文本框的宽度
' 第五个参数:文本框的高度
Set textBox = slide.Shapes.AddTextbox(msoTextOrientationHorizontal, 100, 100, 100, 50)
' 设置文本框内容
textBox.TextFrame.TextRange.Text = initialText
' 设置文本框名称
textBox.Name = "CountdownTextBox"
Next slideIndex
' 开始同步倒计时
StartSyncCountdown
End Sub
Sub StartSyncCountdown()
Dim minutes As Integer
Dim seconds As Integer
Dim totalTime As Integer
Dim slideIndex As Integer
' 初始化时间为 60 分钟
minutes = 60
seconds = 0
totalTime = minutes * 60 ' 转换为总秒数
' 同步倒计时循环
Do While totalTime > 0
' 计算分钟和秒
minutes = totalTime \ 60
seconds = totalTime Mod 60
' 更新每张幻灯片的文本框内容
For slideIndex = 1 To ActivePresentation.Slides.Count
ActivePresentation.Slides(slideIndex).Shapes("CountdownTextBox").TextFrame.TextRange.Text = _
Format(minutes, "00") & ":" & Format(seconds, "00")
Next slideIndex
' 等待1秒
Wait 1
totalTime = totalTime - 1 ' 减少总时间
Loop
' 倒计时结束后,显示“时间到!”
For slideIndex = 1 To ActivePresentation.Slides.Count
ActivePresentation.Slides(slideIndex).Shapes("CountdownTextBox").TextFrame.TextRange.Text = "时间到!"
Next slideIndex
End Sub
Sub Wait(seconds As Single)
Dim endTime As Single
endTime = Timer + seconds
Do While Timer < endTime
DoEvents
Loop
End Sub
alt+f8,运行即可