Results 1 to 2 of 2

Thread: Automated Emails

  1. #1

    Thread Starter
    Registered User
    Join Date
    May 2013
    Posts
    1

    Automated Emails

    Okay total Noob here so please bare with me.
    I used this video to write what I’ve got.
    http://www.youtube.com/watch?v=Z-hsCUl1qW8

    I’m trying to send email notifications, only once, if J14 = <7.0, then stop the emails.
    And then wait for J14 = >6.9, send another email, stop emails and wait for J14 to = <7.0 again.
    Right now it just keeps emailing every 20 minutes when J14 is updated by a web query.

    Any help would be greatly appreciated.
    Thanks

    Here’s what I’ve got.
    ==============================================================
    Private Sub Worksheet_Calculate()

    Control1 = Range("I11").Value

    Trigger = Range("J11").Value

    HighestRecordedPeriod = Range("J14").Select
    If HighestRecordedPeriod < Trigger And Control1 = "MAIL" Then

    Dim ADDRESS As String, SUBJECT As String
    Dim BODY As String, HYPER As String

    ADDRESS = "[email protected]"
    SUBJECT = "This is an Alert - The period has reached " & Range("J14") & " seconds"
    BODY = "test"

    HYPER = "mailto:" & ADDRESS & "?Subject=" & SUBJECT

    ActiveWorkbook.FollowHyperlink (HYPER)
    Application.Wait (Now + TimeValue("0:00:15"))
    Application.SendKeys "%S"

    Range("I11").Select
    ActiveCell.FormulaR1C1 = "MAIL"

    End If
    End Sub

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Automated Emails

    you need some variable to keep track if you want the high value or low value for the next email to be sent, try using a static variable like

    Code:
    static lownext as boolean
    
    if (HighestRecordedPeriod < 7 and not lownext) or (HighestRecordedPeriod > 6.9 and lownext) then
       lownext = not lownext
       ' code to send mail
    end if
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

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



Click Here to Expand Forum to Full Width