MrExcel Publishing
Your One Stop for Excel Tips & Solutions

Wav files in macros

Posted by Kelly on April 02, 2000 8:06 PM

How do I run a wav file within a macro--what is the line expression to put in the code?


Posted by Ivan Moala on April 03, 2000 11:30 PM

Here is a routine that will play sound asynchronously;

Const SND_ASYNC = &H1
Const SND_FILENAME = &H20000

Private Declare Function Playsound Lib "winmm.dll" _
Alias "PlaySoundA" (ByVal lpszName As String, _
ByVal hModule As Long, ByVal dwFlags As Long) As Long

Sub PlaySound()
Dim WAVFile As String
'Name of your sound wave file
WAVFile = "The Microsoft sound.wav"

'The Dir where it resides
WAVFile = "C:\windows\media\" & WAVFile

'The main calling function obtained from win32API doc
Call Playsound(WAVFile, 0&, SND_ASYNC Or SND_FILENAME)

End Sub