Alarm function, disable sound if data is erased

O

offdah3z

Hello all, I'm trying to use an alarm function of Excel. Basically, if A9
is equal to a certain value, for example 213, I would like a sound to be
played. If not, no sound. I seem to have the coding right for this, but
whenever you erase the data in cell A9, the sound plays. Any suggestions?
All your help is appreciated!! My code is below.

=Alarm(A9,"=213")

and the function I used is below

'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 & "\sound.wav"
Call PlaySound(WAVFile, 0&, SND_ASYNC Or SND_FILENAME)
Alarm = True
Exit Function
End If
ErrHandler:
Alarm = False
End Function
 
B

Bernard Liengme

Below I show the line I used to debug the code, and the change I made to fix
your problem
I am unsure why <blank>=213 gets evaluated to TRUE

MsgBox Cell.Value & Condition
If Evaluate(Cell.Value & Condition) And Cell.Value <> "" Then

best wishes
 

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

Similar Threads

Alarm 2 2
Macro Help 4
playing wma files 2
sound 4
Playing wavfiles from excel 3
Run-time error question 0
Problem with playing sound code 3
How does Excel Alarm Function work?? 4

Top