3 sound triggers within the same code

graemeal

Active Member
Joined
May 17, 2007
Messages
316
Platform
  1. Windows
I have this code that triggers sound wavs when a condition has been met. The below has 2 triggers for 2 differant columns. I was wondering can I add a third one to it.

I have tried many variations but so far unsuccessful.

Thanks


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_Calculate()
Const FName1 As String = "C:\WINDOWS\Media\ding.wav"
Const FName2 As String = "C:\WINDOWS\Media\ringin.wav"
Dim h As Range
For Each h In Range("T2:T1896")
    If h.Value > 1.5 Then
        Call PlaySound(FName1, 0&, SND_SYNC Or SND_FILENAME)
        Exit For
    End If
Next h
For Each i In Range("Q2:Q1896")
    If i.Value > 35 Then
        Call PlaySound(FName2, 0&, SND_SYNC Or SND_FILENAME)
        Exit For
    End If
Next i
End Sub


XP SP3 XL 2007
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
This one option I tried. I have also tried it without the extra Const FName3 As String = "C:\WINDOWS\Media\ringin.wav". Calling on FNAME2 twice. As you may guess I really not sure what I am doing.

Thanks


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_Calculate()
Const FName1 As String = "C:\WINDOWS\Media\ding.wav"
Const FName2 As String = "C:\WINDOWS\Media\ringin.wav"
Const FName3 As String = "C:\WINDOWS\Media\ringin.wav"
Dim h As Range
For Each h In Range("T2:T1896")
    If h.Value > 1.5 Then
        Call PlaySound(FName1, 0&, SND_SYNC Or SND_FILENAME)
        Exit For
    End If
Next h
For Each i In Range("Q2:Q1896")
    If i.Value > 35 Then
        Call PlaySound(FName2, 0&, SND_SYNC Or SND_FILENAME)
        Exit For
    End If
Next j
For Each j In Range("R2:R1896")
    If i.Value > 40 Then
        Call PlaySound(FName3, 0&, SND_SYNC Or SND_FILENAME)
        Exit For
    End If
Next j
End Sub
 
Upvote 0
It should be

Rich (BB code):
For Each j In Range("R2:R1896")
    If j.Value > 40 Then
        Call PlaySound(FName3, 0&, SND_SYNC Or SND_FILENAME)
        Exit For
    End If
Next j
 
Upvote 0
Thanks. That was typo error. I meant j but I have just tried it and seems all OK. Not sure what I was doing.

Thanks again
 
Upvote 0

Forum statistics

Threads
1,224,587
Messages
6,179,736
Members
452,940
Latest member
Lawrenceiow

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