|
想在VBA中实现当前时间NOW()与单元格中设定时间相差五分钟,也就是如A1中为12:00:00,当系统时间为11:55:00时,产生声音报警。我是初学者,呵呵,请高手给予解答为盼,谢谢。
附VBA程序和附件如下:
Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long
Private Const SND_ALIAS& = &H10000
Private Const SND_ASYNC& = &H1
Private Const SND_SYNC& = &H0
Private Const SND_NODEFAULT& = &H2
Private Const SND_FILENAME& = &H20000
Private Const SND_LOOP& = &H8
Private Const SND_PURGE& = &H40
Public Const sdDefault = ".Default"
Public Const sdClose = "Close"
Public Const sdEmptyRecycleBin = "EmptyRecycleBin"
Public Const sdMailBeep = "MailBeep"
Public Const sdMaximize = "Maximize"
Public Const sdMenuCommand = "MenuCommand"
Public Const sdMenuPopUp = "MenuPopup"
Public Const sdMinimize = "Minimize"
Public Const sdOpen = "Open"
Public Const sdSystemExclaimation = "SystemExclaimation"
Public Const sdSystemExit = "SystemExit"
Public Const sdSystemHand = "SystemHand"
Public Const sdSystemQuestion = "SystemQuestion"
Public Const sdSystemStart = "SystemStart"
Sub playSystemSound()
Call PlaySound(sdSystemStart, 0&, SND_ALIAS Or SND_ASYNC Or SND_NODEFAULT)
End Sub
Sub PlayWavLoop1()
Call PlaySound(ThisWorkbook.Path & "\trysound.wav", 0&, SND_ASYNC Or SND_LOOP Or SND_NODEFAULT)
WaitMinorSec 5
Call PlaySound(vbNullString, 0&, SND_NODEFAULT)
End Sub
Sub PlayWavLoop2()
Call PlaySound(ThisWorkbook.Path & "\trysound.wav", 0&, SND_ASYNC Or SND_LOOP Or SND_NODEFAULT)
WaitMinorSec 5
Call PlaySound("", 0&, SND_PURGE)
End Sub
Sub PlayWavTest1()
Call PlaySound(ThisWorkbook.Path & "\trysound.wav", 0&, SND_ASYNC Or SND_NODEFAULT)
Call PlaySound(vbNullString, 0&, SND_NODEFAULT)
End Sub
Sub PlayWavTest2()
Call PlaySound(ThisWorkbook.Path & "\trysound.wav", 0&, SND_ASYNC Or SND_NODEFAULT)
Call PlaySound("", 0&, SND_NODEFAULT)
End Sub
Public Sub WaitMinorSec(ByVal dms As Double)
Dim sTimer As Date
sTimer = Timer
Do
DoEvents
Loop While Format((Timer - sTimer), "0.000") < dms
End Sub
我应该在该程序中如何添加,才能实现此功能,谢谢了。 |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|