Play Sound File Once when cell value condition id met

J

John 1

Could someone please explain how I get a sound file to run once the value in
a cell exceeds a specific value.

The cell value contains realtime data and, therefore, I would only want it
to play once (or twice) and then wait until I reset thee trigger value

Thanks in advance,
John
 
J

Jim Thomlinson

This requires macros... I assume you are OK with macros??? How is you comfort
level with macros written from scratch...

Next you need to define real time data... where is the data coming from and
does it trigger the change event in XL or is there some kind of update
routine that can be captured.
 
J

John 1

I am only OK with basic macros.

I have the code from a previous thread in 2006 but once triggered the sound
continues to loop and will not stop until the value goes below the trigger
level.
...............
Option Explicit
Private Declare Function sndPlaySound32 Lib "winmm.dll" Alias _
"sndPlaySoundA" (ByVal lpszSoundName As String, _
ByVal uFlags As Long) As Long

Private Sub Worksheet_Calculate()
If Me.Range("b2").Value > 200 Then
sndPlaySound32 "G:\DATA\scans\New Position.wav", 0
End If
End Sub

.................................
Just need to be able to stop after played once or twice????????????

Thanks,
John
 
J

Jim Thomlinson

Give this a whirl...

Private Declare Function sndPlaySound32 Lib "winmm.dll" Alias _
"sndPlaySoundA" (ByVal lpszSoundName As String, _
ByVal uFlags As Long) As Long

Private m_lngReset As Long

Private Sub Worksheet_Calculate()
If Me.Range("b2").Value > 200 And m_lngReset < 2 Then 'you can change the 2
sndPlaySound32 "G:\DATA\scans\New Position.wav", 0
m_lngReset = m_lngReset + 1
End If
End Sub

'Run this to reset the sound
Public Sub ResetSound()
m_lngReset = 0
End Sub
 
J

John 1

Thanks Jim, appreciate that........ will give it a go on Monday but looks
good to me.

As a point of interest is there a place where I can find the necessary
variables (eg m_lngReset ) and the functions to call?

Is there a way to run the ResetSound routine directly from the worksheet?

Cheers,
John
 

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