.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!
 
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

I'm I putting this as a mod or an active worksheet?
 
Upvote 0

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Well, you need the whole lot

Code:
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)
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

and it goes in the worksheet code module.
 
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

This is still not working for me! though it might be the sheet so created a new one! I don't know what I'm doing wrong with it
 
Upvote 0
Two thoughts:

1) What is changing the value of S41? If you enter a value in S41 then the code should run. If S41 contains a formula then you would need to use the Worksheet_Calculate() event.

2) Are sounds enabled? Try the following in a standard module:

Code:
Sub a()
MsgBox Application.CanPlaySounds
End Sub

If this returns True then sounds are enabled.
 
Upvote 0
Two thoughts:

1) What is changing the value of S41? If you enter a value in S41 then the code should run. If S41 contains a formula then you would need to use the Worksheet_Calculate() event.

2) Are sounds enabled? Try the following in a standard module:

Code:
Sub a()
MsgBox Application.CanPlaySounds
End Sub

If this returns True then sounds are enabled.

Yer its true. and my sound is turned on and working checked that too!

What it does is, S41 gets its info from C40:G40 this is one merged cell, does it with a simple "=C40"

Now C40:G40 gets its info from =SUM(C38,G38) and This is from lots of Tick boxes that give out numbers depending wish ones you tick in what order!
 
Upvote 0
Try this in the worksheet code module instead of what you had previously

Code:
Option Explicit

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_Calculate()
Dim FName As String
Select Case Range("S41").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 Sub
 
Upvote 0
ok still not! so Iv stripped all other codes from that area so no other macros or vb scripts are running, also I've made sure its in the right area and to clarify its

-VBAProject (myworkbook.xls)
-Microsoft Excel Objects
- Sheet
- this workbook
-Modules
- Module1 <<< (code is here!)




Option Explicit

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_Calculate()
Dim FName As String
Select Case Range("S41").Value
Case Is > 99: FName = "tardis.wav"
Case Is > 75: FName = "intel.wav"
Case Else: FName = ""
End Select
If FName <> "" Then Call PlaySound(FName, 0&, SND_ASYNC Or SND_FILENAME)
End Sub

Iv took the C:\ off the files as there in the same directory would this work? only reason is I don't have access to the C:\ drive totally to add files.

hence me using the windows one before! but im trying to keep your code as it is with out altering it too much
 
Upvote 0
what if I refer them to play a file with in excel ? for example "WindowsMediaPlayer1" that I place in as an object? only thing is I don't know the code for that!
 
Upvote 0
The code is in the wrong place.

Right click the sheet's tab, select View Code and put it in there.
 
Upvote 0
The code is in the wrong place.

Right click the sheet's tab, select View Code and put it in there.

ah I had it there originally I misunderstood when ya said put it in the Module

ok it works now kinda! lol it plays it when it goes to past 75 but not when it gets to 100

is away it only plays once when it goes over 75 and some how to make the 2nd wave play atm the intel one still plays not the tardis for the >99 ?
 
Upvote 0

Forum statistics

Threads
1,223,980
Messages
6,175,763
Members
452,668
Latest member
mrider123

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