为了实现音效,我们看下面的代码:#If VBA7 Then Private Declare PtrSafe Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" _ (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long#Else Private Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" _ (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long#End If 'Sound constantsPrivate Const SND_SYNC = &H0Private Const SND_ASYNC = &H1Private Const SND_NODEFAULT = &H2Private Const SND_LOOP = &H8Private Const SND_NOSTOP = &H10 Sub PlayBackLoop() If Len(Dir(ThisWorkbook.Path & "\WheelOfFortune.wav")) > 0 Then WAVLoop ThisWorkbook.Path & "\WheelOfFortune.wav" End IfEnd Sub Sub PlayBackStop() Call WAVPlay(vbNullString)End Sub Sub WAVLoop(File As String) Dim SoundName As String Dim wFlags As Long Dim x As Long SoundName = File wFlags = SND_ASYNC Or SND_LOOP x = sndPlaySound(SoundName, wFlags) If x = 0 Then MsgBox "Can't play the audio file. ", vbCritical, "Error" End Sub Sub WAVPlay(File As String) Dim SoundName As String Dim wFlags As Long Dim x As Long SoundName = File wFlags = SND_ASYNC Or SND_NODEFAULT x = sndPlaySound(SoundName, wFlags) If x = 0 Then MsgBox "Can't play the audio file. ", vbCritical, "Error" End Sub 代码截图:代码的讲解:以上代码实现的是音效的播放和停止,利用的是一个API函数。由于API函数功能强大,但不是VBA范畴,我只是调用,不再过多讲解,如果大家有兴趣,我会送给大家一份相当全的API函数资料。 【分享成果,随喜正能量】 真诚是很珍贵的东西。即使不善言辞,偶尔有些笨,有些迟钝,也没关系。日久见人心,真诚会在时间中闪闪发光。希望你努力做一个真实的人,而不是别人眼中正确的人。时光端午 ,祝福夏安。。 我20多年的VBA实践经验,全部浓缩在下面的各个教程中: