Worksheet Event

  • Hi


    I believe it is possible with Excel 2002 to get it to give audible alerts when an event takes place.


    I use Excel for Currency trading,if cell A1 was greater than the value in cell A2,i would like to generate a sound alert and also to send an email alert.


    I think this can be done with the worksheet event change facility,any help with the code would be greatly appreciated


    Are either of these possible


    Many thanks


    ADE

  • Following code works with MS Outlook.


    Hope this helps ... Interesting requirement BTW ...


    Also if A1 and A2 are calculated fields, please put proper range you want to compare, or if you want to alert / send mail every time there is a change, you may choose to remove the criteria.


    Thanks: ~Yogendra

  • Yogendras excellent code will take care of the email for you.


    This snippet will make the sound:


    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Range("A1").Value > Range("A2").Value And Range("A2") > "" Then
    Beep
    End If
    End Sub


    Regards
    Weasel

  • I would not recommend using the OL object model so as to avoid problems of binding over multiple versions if used on various machines by various users, you would *think* most IT depts would ensure everyone runs on the same version but this is not always the case.


    An alternative example is given below - the same Q I think ADE but in the Email Forum.



    But I think you were using OE which doesn't support VBA anyway so you can't actually automate mail... you could maybe use an SMTP mailer instead.


    Anyway - maybe this will come in handy for other users if not yourself.

  • Firstly i'd like to thank everybody for their time and effort so far.


    I am still working on audible alerts in Excel,the code supplied by
    Pesky Weasel works,i just need to add a few extra features.


    This snippet will make the sound:


    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Range("A1").Value > Range("A2").Value And Range("A2") > "" Then
    Beep
    End If
    End Sub


    Once the Selection Change is triggered,i would like the beep to be REPETATIVE,perhaps beeping once a second and then after ten seconds to shut itself off and RESET itself.The code above makes only one initial beep once the event is triggered, which can be easy to miss,and then every time the mouse pointer is placed in another cell and it doesn't shut itself off.


    The code for this sort of thing is way beyond my abilities,can anybody help please.


    Thanks


    Ade

  • Try the following (modify as desired).


    In your sheet code put

    Code
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Range("A1").Value > Range("A2").Value And Range("A2") > "" And Not ChangeDone Then
        DoBeeps
    End If
    End Sub


    in a module put (note: the public statement needs to be at the top of the module before any subs)

    Code
    Public ChangeDone As Boolean, BeepCount As Integer
    
    
    Sub DoBeeps()
        If BeepCount > 10 Then Exit Sub
        Beep
        BeepCount = BeepCount + 1
        If BeepCount > 10 Then Exit Sub
        Application.OnTime Now + TimeValue("00:00:01"), "DoBeeps"
    End Sub

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!