用VBA做PPT动态倒计时(ppt倒计时软件怎么做)

点击阅读全文

应各类演讲比赛所需,用VBA编写了PPT倒计时文件。可自行设置倒计时时间及到时提前提醒时间,其设置值可继承,直到再次被重新设置为止。具体应用时将标题“用VBA实现倒计时读秒”改为实际所需的标题即可。附属声音文件Ding.wav(计时提醒音)和End,wav(计时结束音),可根据个性偏好,自行用其它声音文件替换。
启动PowerPoint时,请单击菜单“工具”->“宏”->“安全性”,将安全级调整为中或低,以便能使用本文件。

代 码:

Private Declare Function GetTickCount Lib “kernel32.dll” () As Long
Private Declare Sub Sleep Lib “kernel32.dll” (ByVal dwMilliseconds As Long)
Private Declare Function PlaySound Lib “winmm.dll” Alias “sndPlaySoundA” (ByVal lpszName As String, ByVal uFlags As Long) As Long
Const InterVal = 1000 ‘自定义的时间间隔
Dim myStop As Boolean ‘中断计时标识

Private Sub CommandButton1_Click() ‘倒计时开始及中断按钮
Dim preTime, curTime, myTime, jsTime, txTime As Long

Select Case CommandButton1.Caption
Case “开始倒计时”
CommandButton1.Caption = “停止倒计时”
preTime = GetTickCount ‘获得计时开始初始时间
myTime = Val(TextBox2) + 1 ‘所余倒计时时间
jsTime = Val(TextBox2) + 2 ‘总倒计时时间
txTime = Val(TextBox3) ‘倒计时结束前提醒时间
Label3.Visible = False ‘隐藏倒计时输入提示标签
Label4.Visible = False ‘隐藏计时结束前提醒时间输入标签
TextBox2.Visible = False ‘隐藏输入倒计时时间(秒)文本框
TextBox3.Visible = False ‘隐藏输入计时结束前提醒(秒)文本框
Label2.Caption = “计时进行中” ‘计时状态提示标签
Do
curTime = GetTickCount ‘获得当前时间
If curTime – preTime >= InterVal * (jsTime – myTime) Then
myTime = myTime – 1
TextBox1 = myTime ‘显示所余倒计时秒数
DoEvents ‘转让控制权,以便让操作系统处理其它的事件
If myTime = txTime Then
Label2.Caption = “计时将结束”
Call PlaySound(“Ding.wav”, 0&) ‘计时将结束提示音
End If
If myTime = 0 Then
Label2.Caption = “计时时间到”
CommandButton1.Caption = “开始倒计时”
Call PlaySound(“End.wav”, 0&) ‘计时结束提示音
Exit Do
End If
End If
Sleep (20) ‘延时暂停20毫秒
Label1 = Time ‘倒计时中系统实时时间提示标签
DoEvents
If myStop Then
myStop = False
Label2.Caption = “计时被中断”
CommandButton1.Caption = “开始倒计时”
MsgBox “倒计时终止!”, vbInformation + vbOKOnly, “操作提示”
Exit Do
End If
Loop
Case “停止倒计时”
myStop = True
End Select

Label3.Visible = True ‘显示倒计时输入提示标签
Label4.Visible = True ‘显示计时结束前提醒时间输入标签
TextBox2.Visible = True ‘显

                       
上一篇 2021年12月22日 13:34:01
下一篇 2021年12月22日 13:34:32