Macro to Play Wave File

Y

yo beee

I have a macro to play a wave file. It works great (See code below) but,
the macro won't play my wave file all the way through to the end. It plays
about 5 - 10 seconds of the file and that is about it.
Does anyone have any idea on how to make the macro play the entire file
all the way through?
TIA

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

Sub PlayMe1()
Dim retval As Long
retval = PlaySound("C:\My folder\my subfolder\wav1.wav", 0, &H20000)
End Sub
 
T

Tom Ogilvy

Try this:

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

Sub PlayMe1()
Const SND_ASYNC = &H1
Const SND_FILENAME = &H20000
Dim retval As Long
retval = PlaySound("C:\My folder\my subfolder\wav1.wav", _
0, SND_ASYNC Or SND_FILENAME)
End Sub
 
Y

yo beee

Tom,
Thanks! It worked perfectly. Any ideas on how to stop all wav files with
a command button?
Thanks again. Your a lifesaver!
yobeee
 
T

Tom Ogilvy

Untested, but you can try this:

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

Sub StopMe1()
Const SND_PURGE = &H40
Dim retval As Long
retval = PlaySound(vbNullString, _
0, SND_PURGE = &H40)
End Sub

You don't need to repeat the declaration if it is already in the module.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Alarm 2 2
playing wma files 2
Playing wavfiles from excel 3
Macro to play wave file 1
sound 4
Playing a sequence of WAV files 6
Run-time error question 0
Assign a sound to a variable 19

Top