Playing .Wav files via the Windows API : Windows API « Windows API « VBA / Excel / Access / Word






Playing .Wav files via the Windows API

 
Public Declare Function sndPlaySoundA Lib "winmm.dll" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
Public Sub PlayWav(WavFile As String)
    If Application.CanPlaySounds = False Then
        MsgBox "Sorry, sound is not supported on your system."
        Exit Sub
    End If
    If Dir(WavFile) = "" Then
        MsgBox ("Wave file not found")
        Exit Sub
    End If
    sndPlaySoundA WavFile, 1
End Sub
Public Sub TestPlayWav1()
    Dim filePath As String
    filePath = ActiveWorkbook.Path
    PlayWav (filePath & "\Sounds\cannon.wav")
End Sub

 








Related examples in the same category

1.Use 32-bit API declaration
2.Using a Function in a DLL
3.Declaring an External Function to the Compiler
4.Waiting for an application to end