MrExcel Publishing
Your One Stop for Excel Tips & Solutions

playing a wavefile via VBA


Posted by Jason Davis on November 01, 2001 10:36 AM

OK, here we go again...

I am trying to get a wave file to play based on a
value in a cell falling below 31.

Here is what I did (which isn't working)

Declare Function Playsound lib "winmm.dll" _
alias "playsounda" (byval lpszname as string, _
byval hmodule as long, byval dwflags as long) as long

CONST SND_SYNC = &H0
CONST SND_ASYNC = &H1
CONST SND_FILENAME = &H20000

SUB PLAYWAV()

IF WORKSHEETS("514").RANGE("F53") < "31" THEN
WAVFILE = "5VOLT.WAV"
WAVFILE = THISWORKBOOK.PATH & "\" WAVEFILE
CALL PLAYSOUND(WAVFILE. 0&. SND_ASYNC OR SND_FILENAME)

ELSE
END IF
END SUB

I KEEP GETTING AN ERROR MESSAGE OF
"CANT FIND DLL ENTRY POINT PLAYSOUNDA IN WINMM.DLL"

ANY IDEA WHAT THE PROBLEM IS????


Posted by Todd on November 01, 2001 10:44 AM

For one, you are missing an & after "\" but that doesn't sound like the problem. Someone else knows more, but isn't the DLL file what contains the commands you can use? And it seems like you're trying to use the playsounda command in it? So maybe that command is being used incorrectly or is incorrectly named?

Posted by Jason Davis on November 01, 2001 10:50 AM

Its a typo just in here for the & after the "\".

This macro was mostly taken from Microsoft Excel 2000 Power Programming with VBA. I went through it several times looking for errors compaired to the book and it is exactly the same. If you remove the "a" from the "playsounda" it doesnt work at all (compile error)

anyone have any idea???

Posted by Jason Davis on November 01, 2001 11:03 AM

CANT FIND DLL ENTRY POINT PLAYSOUNDA IN WINMM.DLL

Posted by Jason Davis on November 01, 2001 11:05 AM

still hoping for help

Posted by Jason Davis on November 01, 2001 11:09 AM

Juan Pablo, Mark W, anyone??

Posted by Mark W. on November 01, 2001 1:26 PM

Sorry, not my cup of tea (nt)

Posted by Joe Was on November 01, 2001 1:51 PM

Contrary to your Excel 2000 book...

Excel 2000 has had all the play record sounds functions deactivated by Microsoft. The only sounds you can make are the MSO sounds through the "Assistant" or tagging the "Beep" function. Sorry

Your book was probably a rewrite of a older version of Excel which you could play sounds. The sound section of the rewrite was not checked against Excel 2000 and the author did not expect Microsoft to remove such a basic function from the package. Excel 2000 help indicates that this function should not be used?

This is a poor substitute:

Sub myBeep()
'By Joe Was

'The higher the number the longer.
'Pulse is the attack of the waveform.
'Depth is the tone width of the wave form,
'a large width is a lower sound a small width is a higher sound.
'Freq is the tone vibrato (resonance).

'All perimeters are based upon the speed of the computer.
'The fundamental sound is based upon the basic beep function.
'So the range is limited to the fundamental permutations into
'the sharp and flat range of the basic beep with some affects.

'Below diagrams one complete wave form:
'attack - start - brightness, tonal - element, finish.
'Attack 1/4, Attack 2nd 1/4 finish, 3rd 1/4 decay and last 1/4 decay finish.
'It helps to graph your wave form out and to use a tonal scale.

myPulse 320
myDepth 120
myFreq 80

myPulse 20
myDepth 1640
myFreq 160

myPulse 40
myDepth 1320
myFreq 40

myPulse 50
myDepth 140
myFreq 32

End Sub

Sub myPulse(numtones)

For counter = 1 To numtones
Beep
Next counter

End Sub

Sub myFreq(numbeeps)

For counter = 1 To numbeeps
Beep
Next counter

End Sub

Sub myDepth(numbeats)

For F = 1 To numbeats
Next F
For A = 1 To numbeats
Next A
For C = 1 To numbeats
Next C
For E = 1 To numbeats
Next E

End Sub


JSW.

Posted by Ivan F Moala on November 01, 2001 5:42 PM

Re: Juan Pablo, Mark W, anyone??

Try this instead;

Declare Function PlaySound Lib "winmm.dll" Alias "sndPlaySoundA" _
(ByVal lpszName As String, ByVal dwFlags As Long) As Long
Const SND_SYNC = &H0
Const SND_ASYNC = &H1
Const SND_FILENAME = &H20000

Sub PLAYWAV()
Dim wavefile, x
If Worksheets("514").Range("F53") < "31" Then
wavefile = "5VOLT.WAV"
wavefile = ThisWorkbook.Path & "\" & wavefile
Call PlaySound(wavefile, SND_ASYNC Or SND_FILENAME)
End If
End Sub

Ivan

Posted by Jason Davis on November 03, 2001 8:21 AM

Thank you Ivan, works like a champ....thanks again

Declare Function PlaySound Lib "winmm.dll" Alias "sndPlaySoundA" _

Posted by Joe Was on November 07, 2001 2:03 PM

This works in 2000!

Thanks, Ivan:

I never thought of re-addressing "Winmm.dll" to get around Excel 2000's sound problem good going, I like it.

Excel XP has the sound back in and it has "text to Speach."

One problem with the text to speach is it does the whole sheet, I have not been able to to play a cell or range? Joe Was