.wav help for vb

saint_2008

Board Regular
Joined
Sep 6, 2007
Messages
103
This is what I have,

Private 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


Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If UCase(ActiveSheet.Range("S41").Value) > 99 Then
FName = "C:\windows\media\ding.wav"
Call PlaySound(FName, 0&, SND_ASYNC Or SND_FILENAME)
End If
End Sub

but I cant get it to work!

All I want is for it to play a sound when My Value in S41 goes over the Value 99
the value is part of a simple formula of sums.

Cheers for any help, and pointing to the right direction where I'm going wrong with this!
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Cheers for the Help, but It still doesn't work at all

Private 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


Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Range("S41").Value > 99 Then
FName = "C:\windows\media\ding.wav"
Call PlaySound(FName, 0&, SND_ASYNC Or SND_FILENAME)
End If
End Sub

Is there anyway I can get a sound to play easy if the value goes over 99 or what ever value I pick? Iv been trawling the formums taking codes altering them to what I need to no avail. :(



Also what if I need multiple values could I play different sounds? like one to go off at > 75 and another at > 99 ??
 
Last edited:
Upvote 0
The amended code does work - I tested it.

Where have you placed the code - it needs to go in the worksheet code module - right click the sheet tab and select View Code.
 
Upvote 0
The amended code does work - I tested it.

Where have you placed the code - it needs to go in the worksheet code module - right click the sheet tab and select View Code.

Its on my active sheet atm ill change it now see if it works!
 
Upvote 0
Make sure that events are enabled. In the code window press CTRL + G to open the Immediate Window and type in

Application.EnableEvents = True

and press Enter.

By the way, the code as written will play a sound if S41 is >99 and any cell is changed. Is that what you want to happen?
 
Upvote 0
Make sure that events are enabled. In the code window press CTRL + G to open the Immediate Window and type in

Application.EnableEvents = True

and press Enter.

By the way, the code as written will play a sound if S41 is >99 and any cell is changed. Is that what you want to happen?

I want it to play only if 1 cell S41 goes above 99.

did you see my previous comment asking is it also possible to make it so it does multiple values maybe with different sounds?

iv also enabled Application.EnableEvents = True and will try now with the code.
 
Upvote 0
Still no luck at all getting the wav to play. I though this was so simple to do! I guess I was wrong! NO! lol
 
Upvote 0
It works for me. This should do what you want (if you can get the sounds to play!). Note that I changed the filenames and path of the .wav files.

Code:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim FName As String
If Target.Address(False, False) = "S41" Then
    Select Case Target.Value
        Case Is > 99: FName = "C:\tardis.wav"
        Case Is > 75: FName = "C:\intel.wav"
        Case Else: FName = ""
    End Select
    If FName <> "" Then Call PlaySound(FName, 0&, SND_ASYNC Or SND_FILENAME)
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,975
Messages
6,175,749
Members
452,667
Latest member
vanessavalentino83

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top