自己动手,为演示PPT幻灯片开启计时器功能?
发布时间:2023-08-03 09:59:38 作者:22高级攻城师 浏览量:188
简单三步,让你演示PPT时带上计时器功能!
利用VBA宏,复制或者导入文末的宏代码,保存PPT为 .potm(开启宏的模板) 即可(宏代码是PPT模板的一部分,不是插件)。可以把你平常常用的模板计入计时器功能,就不用加载插件了。
操作步骤:
1. 第一步:
打开PPT 的 【开发工具】菜单,如下图,也可以通过 【文件】【选项】进入设置页面,然后点击【开发工具】下的 'Visual basic'编辑器:
第二步:
在VBA编辑器的【插入】菜单(图中步骤),插入一个 '模块'(步骤B), 复制代码到编辑区域,保存即可。
第三步:设置宏安全性
要启用宏代码,需要设置宏安全性,如下图所示,通过【开发工具】-->[宏安全性]进入,或者第一步设置页面的【信任中心】进入。
播放幻灯片时的计时效果:
(时间计时 显示在PPT页面的右下角,每秒钟更新)
宏代码:
(如果觉得有用,可以找我要.txt或.bas宏代码)
#If VBA7 Or Win64 Then
Declare PtrSafe Function SetTimer Lib 'user32' (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As LongPtr) As Long
Declare PtrSafe Function KillTimer Lib 'user32' (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
#Else
Declare Function SetTimer Lib 'user32' (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As LongPtr) As Long
Declare Function KillTimer Lib 'user32' (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
#End If
'
Public index As Integer
Public count As Integer
Public temp As Shape
Public ID As Integer
'
Public Sub TimerProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal idEvent As Long, ByVal dwTime As Long)
count = count + 1
temp.TextFrame.TextRange.Text = TimeSerial(count 3600, (count 60) Mod 60, count Mod 60) '转为时间格式
End Sub
'
Public Sub OnSlideShowPageChange()
If ID <= 0 Then
ID = SetTimer(win_hwnd, 1000, 1000, AddressOf TimerProc)
Set temp = ActivePresentation.Designs(1).SlideMaster.Shapes.AddTextbox(msoTextOrientationHorizontal, ActivePresentation.PageSetup.SlideWidth - 70, ActivePresentation.PageSetup.SlideHeight - 20, 75, 25) '
'temp.Name = 'Time'
temp.ZOrder (msoBringToFront)
With temp.TextFrame.TextRange
.Font.Name = 'Arial' '文本框字体
.Font.Size = 12 '文本框字体大小
.Text = '0:00:00' '文本框文字
End With
Else
temp.TextFrame.TextRange.Text = ''
End If
End Sub
'
Public Sub OnSlideShowTerminate()
tt = KillTimer(0, ID)
temp.Delete
count = 0
ID = 0
End Sub
收藏