+ Reply to Thread
Results 1 to 17 of 17

Send email when are date past

Hybrid View

  1. #1
    Registered User
    Join Date
    07-09-2008
    Location
    Singapore
    Posts
    13

    Send email when are date past

    Hi,
    This is my first post in this forum. I hope to find the answer to my request.
    I have a workbook that records incoming mail and each of these mail need to be responded to. I like to have a macro that can automatically send a standard notification email when certain condition are met.
    In this workbook the date of receipt of mail is in Col. D and date of Reply in Col. E. If Col E is blank or 30 days later than Col. D a standard email is sent to the email account of the person in Col. F. Col. F shows the email address only.
    The body of the email is
    Please take note you have not responded to the letter sent by (Col. C addresses) as registered in the Letter Register.
    Appreciate all the help I can get.

  2. #2
    Forum Contributor SOS's Avatar
    Join Date
    01-26-2004
    Location
    Glasgow, Scotland
    MS-Off Ver
    Excel 2003
    Posts
    327
    Hi Hyperbole,

    You could use the following code (taken from Ron De Bruin's site) and adapted for you.

    Sub Mail_small_Text_Outlook()
    ' Is working in Office 2000-2007
        If Range("E1").Value > Range("D1").Value + 30 Or Range("E1").Value = "" Then
        Dim OutApp As Object
        Dim OutMail As Object
        Dim strbody As String
     
        Set OutApp = CreateObject("Outlook.Application")
        OutApp.Session.Logon
        Set OutMail = OutApp.CreateItem(0)
     
        strbody = "Please take note you have not responded to the letter sent by " & Range("C1").Value & " as registered in the Letter Register."
     
        On Error Resume Next
        With OutMail
            .To = Range("F1").Value
            .CC = ""
            .BCC = ""
            .Subject = "This is the Subject line"
            .Body = strbody
            '.Send   'or use
            .Display
        End With
        On Error GoTo 0
     
        Set OutMail = Nothing
        Set OutApp = Nothing
    Else
    End If
    End Sub
    However since your request states you want this message sent when 1 of 2 conditions is met it will send an email if Col E is blank. Are you sure you want this?
    Hope this helps

    Seamus

  3. #3
    Registered User
    Join Date
    07-09-2008
    Location
    Singapore
    Posts
    13
    SOS,

    To be more precise the conditions should be the today date is more than 30 days than Col D and Col E is blank.

    As I am not very well verse with VBA I like to know if the codes you have graciously provided will loop through all the rows so that an email will be sent to each of the recipient if the conditions are met.
    Last edited by Hyperbole; 07-09-2008 at 03:52 AM.

  4. #4
    Registered User
    Join Date
    07-09-2008
    Location
    Singapore
    Posts
    13
    I like to reiterate that the conditions for which this macro should run are
    1. The current date is more than 30 after the date of the receipt of the date as shown in Col. D and if Col. E is blank. This mean only when both conditions are met will this macro execute. This macro should execute once the workbook is open.
    I tried the codes it only execute for one row it does not loop through all the rows so that an email is sent whenever the above conditions are met. My data start from row 8 downward. One important thing to consider and that is this macro should stop at the first empty row at the end of the data.

  5. #5
    Forum Contributor SOS's Avatar
    Join Date
    01-26-2004
    Location
    Glasgow, Scotland
    MS-Off Ver
    Excel 2003
    Posts
    327
    Hi Hyperbole,

    Try this amended code

    Sub Send_Mail()
    Dim rng As Range
    Dim cel As Range
    Dim LastCel As String
    Dim szToday As String
    Dim OutApp As Object
    Dim OutMail As Object
    Dim strbody As String
         
    LastCel = Range("D65536").End(xlUp).Address
    szToday = Format(Date, "dd/mm/yyyy")
    
    Set rng = Range("D8:" & LastCel)
        For Each cel In rng
            If DateDiff("d", cel, Now) > 30 And cel.Offset(0, 1).Value = "" Then
                Set OutApp = CreateObject("Outlook.Application")
                OutApp.Session.Logon
                Set OutMail = OutApp.CreateItem(0)
                    strbody = "Please take note you have not responded to the letter sent by " & Range("C1").Value & " as registered in the Letter Register."
         On Error Resume Next
            With OutMail
                .To = Range("F1").Value
                .CC = ""
                .BCC = ""
                .Subject = "This is the Subject line"
                .Body = strbody
                '.Send   'or use
                .Display
            End With
        On Error GoTo 0
     
        Set OutMail = Nothing
        Set OutApp = Nothing
            Else
            End If
        Next cel
    End Sub
    Of course that code would have to be placed in the Workbook_Open part of your book. Post back if you need any help in that direction

  6. #6
    Registered User
    Join Date
    07-09-2008
    Location
    Singapore
    Posts
    13
    SOS,

    All seem to works well based on the current codes. I just like to push the performance a little bit more and that is to enable this macro to run whenever either this file is open or there is any change to the worksheet.

    Thanks in advance

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1