|
本帖最后由 adad321 于 2023-7-7 21:46 编辑
填写时间,点击启动,到时间后弹出消息,响起提示音。
- Option Explicit
- Private Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
- Private Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
- Private Const WM_TIMER As Long = &H113
- Private timerID As Long
- Private Sub TimerProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal idEvent As Long, ByVal dwTime As Long)
- Dim targetTime As Date
- Dim currentTime As Date
-
- targetTime = Range("H2").Value ' 获取H2单元格中的时间
- currentTime = Now ' 获取当前时间
-
- If Format(currentTime, "hh:mm:ss") = Format(targetTime, "hh:mm:ss") Then ' 判断当前时间是否等于目标时间
- MsgBox "时间到了!" ' 弹出消息框
- Beep ' 播放提示声音
- KillTimer hwnd, idEvent ' 停止定时器
- End If
- End Sub
- Sub StartTimer()
- timerID = SetTimer(0, 0, 1000, AddressOf TimerProc) ' 启动定时器,间隔为1秒
- End Sub
- Sub StopTimer()
- KillTimer 0, timerID ' 停止定时器
- End Sub
复制代码
|
评分
-
2
查看全部评分
-
|