以WAV格式播放声音文件很容易。您只需要知道要播放的声音的文件名,并确定是否要宏在声音播放时等待即可。

这是一个示例:

Public Declare Function sndPlaySound Lib "winmm.dll" _

Alias "sndPlaySoundA" (ByVal lpszSoundName As String, _

ByVal uFlags As Long) As Long

Sub PlayWavFile(WavFileName As String, Wait As Boolean)

If Dir(WavFileName) = "" Then Exit Sub ' no file to play

If Wait Then ' play sound before running any more code

sndPlaySound WavFileName, 0

Else ' play sound while code is running

sndPlaySound WavFileName, 1

End If

End Sub

Sub TestPlayWavFile()

PlayWavFile "c:\foldername\soundfilename.wav", False

MsgBox "This is visible while the sound is playing..."

PlayWavFile "c:\foldername\soundfilename.wav", True

MsgBox "This is visible after the sound is finished playing..."

End Sub