Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel VBA Alarm function incorrectly returns FALSE 1

Status
Not open for further replies.

gertbr

Technical User
Aug 4, 2009
10
0
0
FR
I am trying to configure an alarm based on the value of a cell which is linked to a web query
The formula is:
=Alarm(D7;">=1")

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

Why does the Alarm formula return True in cels E3 when the condition is referenced to D3 while the same Alarm function returns False in cels E5,6,7 & 9 when the condition is referenced to D5,6,7 & 9 (where the value clearly exceeds 1).

I would like the Alarm function to work with cel reference D7.

I really appreciate your comments and hope you can point me in the right direction.

 



Well its CLEARLY not meeting the condition, although it APPEARS to. Look at your DATA.

Your code works just fine, as I have just triggered Randy Travis singing InTheGarden.wav

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Skip,

Thanks for your comments! There must be something with the comma format. When I replace the 5 in cel D3 with 12,54 the alarm function doesn`t work, but when I enter 12.54 in cel D3 it works again. Not sure though how to fix the problem though. Could you give some more hints please.....
Regards,
Gert
 



the formula you posted referencs D7.

Is the formula of concern referencing D5 for sure?

It works perfectly for me, and I cannot replicate what you describe.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Skip,
There are 5 different alarm function references in the linked file. I did this to show that the formula works when the reference is D3, but doesn´t work when the reference is D5,6,7 or 9.

What I really don´t understand is that other people open the file and everything seems to be fine, i.e. the alarm works properly on all 5 cels??????

Any thoughts on why this only doesn't seem to work on my PC would be very welcome.

Regards,
Gert
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top