Consulting

Results 1 to 12 of 12

Thread: Solved: Sound alert

  1. #1
    VBAX Tutor
    Joined
    Sep 2008
    Posts
    213
    Location

    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]

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    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'

  3. #3
    VBAX Tutor
    Joined
    Sep 2008
    Posts
    213
    Location
    thats great md, is there a simple way to continuously play the wav file until the condition changes?

  4. #4
    VBAX Tutor
    Joined
    Sep 2008
    Posts
    213
    Location
    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.

  5. #5
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    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'

  6. #6
    VBAX Tutor
    Joined
    Sep 2008
    Posts
    213
    Location
    sorry md, I might not be understadning this, I changed the Interval seconds to 20, but it still only plays once

  7. #7
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    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'

  8. #8
    VBAX Tutor
    Joined
    Sep 2008
    Posts
    213
    Location
    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

  9. #9
    VBAX Tutor
    Joined
    Sep 2008
    Posts
    213
    Location
    Tried this again today, and it worked fine. Thanks a lot for your help

  10. #10

    Speak

    Another fun alternative can be to use the Speech Object.

    [VBA]application.Speech.Speak "Hey, look at this."[/VBA]

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

  12. #12

    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
  •