使用Office2003 VBA制作有倒计时功能的PPT

  1. 新建一个PPT
  2. 设计好背景界面
  3. 点击菜单视图-工具栏-Visual Basic
  4. 点击图示,拖动按钮到界面上

  5. 拖到界面的按钮上点右键,选择“属性”

  6. 在Caption输入“开始倒计时”

  7. 如下图所示,再拖动几个控件到界面上

  8. 在按钮上点右键,选择“查看代码”(或按键Alt+F11,打开VBA编程环境,后双击Slide1)
  9. ff
  10. 输入代码
    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 '自定义的时间间隔
    
    Private Sub CommandButton1_Click()
    
    Static State, myStop As Boolean
    Dim preTime, curTime, myTime, jsTime, txTime As Long
    If State Then myStop = True: Exit Sub
    CommandButton1.Caption = "停止倒计时"
    State = True
    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
                State = False
                myStop = False
                CommandButton1.Caption = "开始倒计时"
               ' Call PlaySound("End.wav", 0&)
                Exit Do
            End If
        End If
        Sleep (20)
        Label1 = Time
        DoEvents
        If myStop Then
            State = False
            myStop = False
            CommandButton1.Caption = "开始倒计时"
            MsgBox "倒计时终止!", vbInformation + vbOKOnly, "操作提示"
            Exit Do
        End If
    Loop
    Label2.Caption = "计时时间到"
    Label3.Visible = True
    Label4.Visible = True
    TextBox2.Visible = True
    TextBox3.Visible = True
    End Sub
    

  11. 保存后,按Shift+F5 , 演示。在请输入倒计时时间(秒)填入60,在倒计时结束前提醒(秒)填入5,点击“开始倒计时”按钮。
资源下载:
http://download.csdn.net/detail/xundh/9692346
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

编程圈子

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值