用VBA实现了个高考倒计时的PPT,代码如下:
Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
Public mTimer As Long
Sub timer()
ss = DateDiff("s", Now, "2020-7-7 00:00:00")
dd = ss \ 86400
hh = (ss Mod 86400) \ 3600
mm = (ss Mod 3600) \ 60
ss = ss Mod 60
ActivePresentation.Slides(1).Shapes(1).TextFrame.TextRange.Text = dd & "天" & hh & "小时" & mm & "分钟" & ss & "秒"
End Sub
Sub start()
mTimer = SetTimer(0, 0, 1000, AddressOf timer)
End Sub
Sub OnSlideShowPageChange()
Call start
End Sub
Sub OnSlideShowTerminate()
mTimer = KillTimer(0, mTimer)
Application.Quit
End Sub
有时候,ppt版本可能会导致PPT播放时不能自动开始计时,网上给出了一个解决办法,就是:在当前幻灯片页加入一个小控件,可以设置为透明,或者隐藏起来。
1.gif
网友评论