-
Solved: Sound alert
I'm trying to setup a sound alert for when a cell's value exceeds a certain value. Ive tried the following and it seems to work ok when I run it as a macro, but this doesnt help me much.
I would like it to just run constantly, as part of the spreadsheet, to alert me when a dynamically changing cell value (its a stock price) exceeds a certain value and will continue to run until the value goes back under the alert prcie or is stopped (planning to add a popup with a stop button later)
[VBA]
'========================================================================== ======
'- SIMPLE METHOD : PLAY A WAV FILE
'- Requires winmm.dll
'- Brian Baulsom October 2008
'========================================================================== ======
Private Declare Function mciExecute Lib "winmm.dll" _
(ByVal lpstrCommand As String) As Long
Dim WAVfile As String
'========================================================================== =======
'- CHECK CELL VALUE
'========================================================================== =======
Sub CheckCellValue()
If Range("A1").Value > 99 Then
PlayFile
End If
End Sub
'========================================================================== =======
'- PLAY THE FILE
'========================================================================== =======
Sub PlayFile()
WAVfile = "C:\Sounds\Sound.wav"
mciExecute ("play " & WAVfile)
End Sub
[/VBA]
-
This uses a timer to change a value and trigger your sound code.
MVP (Excel 2008-2010)
Post a workbook with sample data and layout if you want a quicker solution.
To help indent your macros try Smart Indent
Please remember to mark threads 'Solved'
-
thats great md, is there a simple way to continuously play the wav file until the condition changes?
-
Just tried to copy the alert code to a new spreadsheet, but it doesnt react to a change in cell A1, do I need to copy something else across from your sheet? I dont need the number generator section
Actually , just figured it out. Was able to replicate it in a new sheet.
-
Set the timer to suit the wav length and call the start command from the called procedure.
[VBA]
Sub TheSub()
''''''''''''''''''''''''
PlayFile
''''''''''''''''''''''''
StartTimer ' Reschedule the procedure
End Sub
[/VBA]
MVP (Excel 2008-2010)
Post a workbook with sample data and layout if you want a quicker solution.
To help indent your macros try Smart Indent
Please remember to mark threads 'Solved'
-
sorry md, I might not be understadning this, I changed the Interval seconds to 20, but it still only plays once
-
Can you post your own code, if it's not confidential.
MVP (Excel 2008-2010)
Post a workbook with sample data and layout if you want a quicker solution.
To help indent your macros try Smart Indent
Please remember to mark threads 'Solved'
-
I just actually adjusted the sheet you posted, changing hte time to 50 seconds, however the wav file only places once.
I also tried manually changinfthe value of the cell, it only plays the file once as well
-
Tried this again today, and it worked fine. Thanks a lot for your help
-
Speak
Another fun alternative can be to use the Speech Object.
[VBA]application.Speech.Speak "Hey, look at this."[/VBA]
-
If you are using Windows 7 and Excel 2007 I don't think that Speech is available. I think I read somewhere that Microsoft removed it in the new systems. You might want to check it out.
Sid
PS. Also you might try the Beep command.
-
Speech
I use it on Win 7 with Excel 2007. Still available.
As of Vista, the voice changed to a more female version as compared to the XP voice.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules