Playing a sound base on cell value

  • Thread starter Thread starter Mike
  • Start date Start date
M

Mike

Hello all,

I have an excel sheet that updates every 2 seconds from an
SQL server that is fed by a PLC. I am monitoring the speed
of a manufacturing line. I want a wave file to play if the
line stops (cell value=0). I found the code for calling
sounds, but how do I get it to play once, after the cell
equals 0? I assume the code would be similar to play a
different sound when the line starts back up again?

Windows 2000
Excel 2000

Thanks,
Mike
 
You might consider declaring a global variable in your module that contains
the reference of the last cell on which your code beeped. Then, in your
sub, check to see if it's trying to beep on the same cell. If it is the
same cell, just skip the beep. If not, beep, and then set the variable to
the current cell on which it's beeping.

For something specific to your code, post your code.

/i.
 
John,
Thanks a bunch. I've been through the tips on JW's
site and only remember the generic sound tip.

Thanks for the redirect,

Mike
 
-----Original Message-----
You might consider declaring a global variable in your module that contains
the reference of the last cell on which your code beeped. Then, in your
sub, check to see if it's trying to beep on the same cell. If it is the
same cell, just skip the beep. If not, beep, and then set the variable to
the current cell on which it's beeping.

For something specific to your code, post your code.

/i.




.
'Windows API function declaration
Private Declare Function PlaySound Lib "winmm.dll" _
Alias "PlaySoundA" (ByVal lpszName As String, _
ByVal hModule As Long, ByVal dwFlags As Long) As Long


Function Alarm(Cell, Condition)
Dim WAVFile As String
Const SND_ASYNC = &H1
Const SND_FILENAME = &H20000
On Error GoTo ErrHandler
If Evaluate(Cell.Value & Condition) Then
WAVFile = ThisWorkbook.Path & "\go.wav" 'Edit this
statement
Call PlaySound(WAVFile, 0&, SND_ASYNC Or
SND_FILENAME)
Alarm = True
Exit Function
End If
ErrHandler:
Alarm = False
End Function

function is
=Alarm(A3,"D2=0")
 
Back
Top