VBA中使用计时器的两种方法
2016-12-01 14:48
204 查看
'================================ ' VBA采用Application.OnTime实现计时器 ' ' http://www.cnhup.com '================================ Public RunWhen As Double Public Const cRunIntervalSeconds = 120 ' two minutes Public Const cRunWhat = "TheSub" ' the name of the procedure to run Sub StartTimer() RunWhen = Now + TimeSerial(0,0,cRunIntervalSeconds) Application.OnTime EarliestTime:=RunWhen, Procedure:=cRunWhat, _ Schedule:=True End Sub Sub TheSub() StartTimer ' Reschedule the procedure End Sub Sub StopTimer() On Error Resume Next Application.OnTime EarliestTime:=RunWhen,Procedure:=cRunWhat, _ Schedule:=False End Sub
'================================ ' VBA采用Windows API实现计时器 ' ' http://www.cnhup.com '================================ Public Declare Function SetTimer Lib "user32" ( _ ByVal HWnd As Long, _ ByVal nIDEvent As Long, _ ByVal uElapse As Long, _ ByVal lpTimerFunc As Long) As Long Public Declare Function KillTimer Lib "user32" ( _ ByVal HWnd As Long, _ ByVal nIDEvent As Long) As Long Public TimerID As Long Public TimerSeconds As Single Sub StartTimer() TimerSeconds = 1 ' how often to "pop" the timer. TimerID = SetTimer(0&, 0&, TimerSeconds * 1000&, AddressOf TimerProc) End Sub Sub EndTimer() On Error Resume Next KillTimer 0&, TimerID End Sub Sub TimerProc(ByVal HWnd As Long, ByVal uMsg As Long, _ ByVal nIDEvent As Long, ByVal dwTimer As Long) '''''' ' This procedure is called by Windows. Put your ' code here. '''''' End Sub
相关文章推荐
- 可使用两种方法之一生成窗体身份验证 Cookie,并将用户重定向到 cmdLogin_ServerClick 事件中的相应页。
- RSS制作(C#) - 使用XML DOM和XmlTextWriter(见评论)两种方法
- 使用SQL Server存储过程中的返回值的两种方法
- 使用JavaScript实现CheckBoxList单选两种方法
- AJAX最基本的两种使用方法
- 在delphi中使用xml文档有两种方法
- 使用Ajax SlideShowExtender传参的两种方法(.net 2.0/3.5)
- 使用VC连接Access数据库的两种方法
- Maven使用第三方jar文件的两种方法
- 在 App_Code 文件夹中同时使用两种语言编程的方法
- Javascript里的两种使用正则的方法
- RDCL报表的两种使用方法/为DataSet添加两个Table_AX
- RSS制作(C#) - 使用XML DOM和XmlTextWriter(见评论)两种方法
- HTMLParser的两种使用方法
- Eclipse中perspective(透视图)的两种使用方法详解
- VB.NET中使用FTP下载文件的两种方法。
- 使用Hibernate过滤集合元素的两种方法
- 控件开发时两种JS嵌入资源方式的使用方法
- VB.NET中使用FTP下载文件的两种方法
- srand()及rand()随机函数使用的两种方法-技术原创。