Stop .wav file with button after started playing

mewingpants

New Member
Joined
Apr 1, 2019
Messages
12
So currently I am using this soundme code to play a .wav file

Code:
#If Win64 Then    Private Declare PtrSafe Function PlaySound Lib "winmm.dll" _
        Alias "PlaySoundA" (ByVal lpszName As String, _
        ByVal hModule As LongPtr, ByVal dwFlags As Long) As Boolean
[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=Else]#Else[/URL] 
    Private Declare Function PlaySound Lib "winmm.dll" _
        Alias "PlaySoundA" (ByVal lpszName As String, _
        ByVal hModule As Long, ByVal dwFlags As Long) As Boolean
[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=End]#End[/URL]  If
Const SND_SYNC = &H0
Const SND_ASYNC = &H1
Const SND_FILENAME = &H20000
Function SoundMe() As String
'Updateby Extendoffice 20161223
    Call PlaySound("siren.wav", _
      0, SND_ASYNC Or SND_FILENAME)
    SoundMe = ""
End Function

Then I use this code to play the siren.wav if E15 is greater than 146772

Code:
=IF(E15>146772,SoundMe(),"")

This all works great, the siren plays if E15 is greater than the value.

What I would like to do if possible is, have a "Acknowledge" button that will quit playing the siren.wav

This is just so whoever is putting in a value that exceeds E15 the siren goes off and they have to manually 'ack' the alarm by pressing the button.


Sorry if this has been asked before but I have searched this forum and googled this, I couldn't find anything that was as specific as to what I would like it to do.

*note* the siren wav is not looped but it is rather long siren on purpose @ 15 seconds, so it does stop on its own. This is just so the user will see their problem and try to correct it.

Version: MS for Office 365 32-bit
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Simplest way is to attach a shortcut to a macro that plays a very short sound
- terminates original wav and plays ShortWav
- perhaps shortcut {CTRL} Q (Q for Quiet!)

Code:
Sub SoundX()
    Const ShortWav = "C:\Windows\media\Windows Feed Discovered.wav"
    Call PlaySound(ShortWav, 0, SND_ASYNC Or SND_FILENAME)
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,279
Members
452,630
Latest member
OdubiYouth

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