View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Mike[_58_] Mike[_58_] is offline
external usenet poster
 
Posts: 18
Default Playing a sound base on cell value


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

"Mike" wrote in

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



.

'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")