Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 7
Default Alarm function, disable sound if data is erased

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
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1,104
Default Alarm function, disable sound if data is erased

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
--
Bernard V Liengme
Microsoft Excel MVP
http://people.stfx.ca/bliengme
remove caps from email


"offdah3z" wrote in message
...
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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to add sound ( beep ) if cell content changes in live data Bhavana Excel Discussion (Misc queries) 1 August 28th 08 07:55 PM
How Do I Recover the Erased Data [email protected] Excel Worksheet Functions 1 August 8th 07 02:34 PM
CAN EXCELL SOUND AN ALARM ? DWATERS Excel Discussion (Misc queries) 2 February 1st 07 10:17 PM
Sound on data entry gord Excel Discussion (Misc queries) 2 July 30th 06 12:13 AM
adding sound to an excel i.e. warning if data is negative CDG Excel Discussion (Misc queries) 6 March 11th 06 10:39 PM


All times are GMT +1. The time now is 06:04 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"