分享

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

 本明书馆 2016-10-22

来自 谢厂节的博客

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

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

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

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

  8. 在按钮上点右键,选择“查看代码”(或按键Alt+F11,打开VBA编程环境,后双击Slide1)
  9. ff
  10. 输入代码
    [vb] view plain copy
     在CODE上查看代码片派生到我的代码片
    1. Private Declare Function GetTickCount Lib "kernel32.dll" () As Long  
    2. Private Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)  
    3. 'Private Declare Function PlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszName As String, ByVal uFlags As Long) As Long  
    4. Const InterVal = 1000 '自定义的时间间隔  
    5.   
    6. Private Sub CommandButton1_Click()  
    7.   
    8. Static State, myStop As Boolean  
    9. Dim preTime, curTime, myTime, jsTime, txTime As Long  
    10. If State Then myStop = TrueExit Sub  
    11. CommandButton1.Caption = "停止倒计时"  
    12. State = True  
    13. preTime = GetTickCount  
    14. myTime = Val(TextBox2) + 1  
    15. jsTime = Val(TextBox2) + 2  
    16. txTime = Val(TextBox3)  
    17. Label3.Visible = False  
    18. Label4.Visible = False  
    19. TextBox2.Visible = False  
    20. TextBox3.Visible = False  
    21. Label2.Caption = "计时进行中"  
    22. Do  
    23.     curTime = GetTickCount  
    24.     If curTime - preTime >= InterVal * (jsTime - myTime) Then  
    25.         myTime = myTime - 1  
    26.         TextBox1 = myTime  
    27.         DoEvents  
    28.         If myTime = txTime Then  
    29.             Label2.Caption = "计时将结束"  
    30.            ' Call PlaySound("Ding.wav", 0&)  
    31.         End If  
    32.         If myTime = 0 Then  
    33.             State = False  
    34.             myStop = False  
    35.             CommandButton1.Caption = "开始倒计时"  
    36.            ' Call PlaySound("End.wav", 0&)  
    37.             Exit Do  
    38.         End If  
    39.     End If  
    40.     Sleep (20)  
    41.     Label1 = Time  
    42.     DoEvents  
    43.     If myStop Then  
    44.         State = False  
    45.         myStop = False  
    46.         CommandButton1.Caption = "开始倒计时"  
    47.         MsgBox "倒计时终止!", vbInformation + vbOKOnly, "操作提示"  
    48.         Exit Do  
    49.     End If  
    50. Loop  
    51. Label2.Caption = "计时时间到"  
    52. Label3.Visible = True  
    53. Label4.Visible = True  
    54. TextBox2.Visible = True  
    55. TextBox3.Visible = True  
    56. End Sub  

  11. 保存后,按Shift+F5 , 演示。在请输入倒计时时间(秒)填入60,在倒计时结束前提醒(秒)填入5,点击“开始倒计时”按钮。

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约