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
我用的DATEDIFF函数,只在VBA中能用, 工作表中不可用. now()-today()这个求出来的不是分钟.NOW返回当前日期时间, TODAY只返回当前日期.作者: jxcxf8100 时间: 2010-4-29 16:33
您能把上面的逐语句给我解释下吗?我真的很笨,但我很执着,我是初学者,谢谢您。我还是没弄清楚,本来在家的时间不长,一月能在家间休五天左右,呵呵。这个问题困扰我很久了!!!作者: 方漠 时间: 2010-5-1 10:24
Public Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long
'声明调用API函数 Playsound
Sub TestPlay()
Dim DD As Date '定义函数DD为日期型数据
DD = [A1] 'DD等于A1单元格输入的日期时间
Do '开始循环
If DateDiff("n", Now(), DD) <= 5 Then '如果系统当前时间与DD的时间间隔小于等于5分钟, Playsound
PlaySound ThisWorkbook.Path & "\trysound.wav", 0&, &H1
End If
DoEvents '响应用户控制
Loop While DateDiff("n", Now(), DD) >= 2 '如果系统当前时间与DD的时间间隔大于等于2分钟, 继续循环,即会连续PlaySound 3分钟