ERLANDSEN DATA CONSULTING Excel & VBA Tips   Informasjon på norsk / Information in Norwegian

These pages are no longer updated and are only available for archive purposes.

Click here to visit the pages with updated information.

Playing WAV-files

It's easy to play soundfiles in WAV-format. You only need to know the filename of the sound you want to play, and decide if you want the macro to wait while the sound plays or not. Here is an example:

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

 

Document last updated 1999-08-13 12:50:38      Printerfriendly version

 

Erlandsen Data Consulting     http://www.erlandsendata.no/   
Excel & VBA Tips   Copyright ©1999-2024    Ole P. Erlandsen   All rights reserved
E-mail Contact Address