How to initiate a sound via VBA?

  • Thread starter Hartmut \(Harry\) Kloppert
  • Start date
H

Hartmut \(Harry\) Kloppert

At a certain event (push button) I would like to have
a sound (.wav) file being played.
Any advise?

(for a test, I reconfigured the "Default Beep" in Windows
to the desired wav-ile. And then programm a simple
"Beep" in VBA. But that (of course) gives me a lot
of strange sounds at many other windows-events...)

Hary
 
S

Steve Yandl

Here is one that will make a pinball machine sound if you enter a value
greater than 15 in cell C2. Just grab the inner portion of the If...Then
block, put it in your sub for the button press and change to the wav file of
your choice.

'-----------------------------------------

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$C$2" Then
Application.EnableEvents = False
If Target.Value >= 15 Then
strWavPath = "C:\Program Files\Windows NT\Pinball\SOUND36.wav"
x = Shell("sndrec32 /play /close " & Chr(34) & strWavPath & Chr(34),
vbHide)
End If
Application.EnableEvents = True
End If
End Sub


'----------------------------------------

Steve Yandl
 

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

Top