Error Checking in Excel
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 4 of 4

Thread: sound

  1. #1
    New Member
    Join Date
    May 2002
    Posts
    1
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    How do i get excel to play a wav file if a cell satisfies a certain condition??
    For example, if a1 > 25 then play
    beep.wav

    Thanks for any help


  2. #2
    New Member
    Join Date
    Apr 2002
    Location
    Kansas City, MO
    Posts
    14
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    =Alarm(A1,">=1000")
    The sound will play when the value in cell A1 is greater than or equal to 1,000.

    =Alarm(C12,"<0")
    The sound will play when the value in cell C12 is negative.

    OR VBA EXAMPLE:

    '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" 'Edit this statement
    Call PlaySound(WAVFile, 0&, SND_ASYNC Or SND_FILENAME)
    Alarm = True
    Exit Function
    End If
    ErrHandler:
    Alarm = False
    End Function

    If you do not change the path of the sound file, it will just use a default sound. The program will first look for the file in the same path as the workbook, if not there, default sound will play. Unless you put the correct path if the sound is somewhere else.

    Enjoy.


  3. #3
    MrExcel MVP
    Join Date
    Feb 2002
    Location
    Millbank, London, UK
    Posts
    1,790
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Datastream

    which version of excel does this function appear in ?

    it's not in '97...

  4. #4
    MrExcel MVP
    Join Date
    Feb 2002
    Location
    Sydney, Australia
    Posts
    2,940
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default

    Chris,

    The UDF Alarm is posted below his explanation. There's no built in Alarm function in Excel 2000 either (and presumably not XP)

    EDIT - However, on re-reading the post it does imply that there is a non-VBA and a VBA way of doing it - hmmmmmmm...let's see

    Cheers,
    Dan

    [ This Message was edited by: dk on 2002-05-08 12:41 ]

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •