+ Reply to Thread
Results 1 to 22 of 22

Macro to send email upon certain date trigger

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    02-01-2011
    Location
    london, england
    MS-Off Ver
    Excel 2016
    Posts
    179

    Macro to send email upon certain date trigger

    Hi guys,

    I think this is super complicated and i can't get it to work even a little bit...

    i need excel to, upon opening a workbook, send an email if a condition is met, that condition being a date in a cell passing ONLY if adjacent cell is blank.

    for example, in column A we have a list of dates, and if the date in A2 passes and B2 is blank, i need it to trigger an email sent to one fixed recipient, preferably with the title of the workbook within the body or title of the email.

    Can someone help me?

    If any more information is needed please ask!

    EDIT* thinking about it, this doesn't seem like a macro is needed, perhaps an active function type thing? (forgive the lack of technical jargon)
    Last edited by fabrecass; 01-11-2013 at 12:17 PM.

  2. #2
    Forum Contributor
    Join Date
    02-01-2011
    Location
    london, england
    MS-Off Ver
    Excel 2016
    Posts
    179

    Re: Macro to send email upon certain date trigger

    bump

    no one?

  3. #3
    Forum Contributor
    Join Date
    02-01-2011
    Location
    london, england
    MS-Off Ver
    Excel 2016
    Posts
    179

    Re: Macro to send email upon certain date trigger

    guys?! is this crazy complicated or do i smell?

  4. #4
    Valued Forum Contributor john55's Avatar
    Join Date
    10-23-2010
    Location
    Europe
    MS-Off Ver
    Excel for Microsoft 365
    Posts
    2,060

    Re: Macro to send email upon certain date trigger

    hi, try the attachement and see if it heps you!
    http://www.excelforum.com/excel-gene...coming-up.html
    Attached Files Attached Files
    Regards, John55
    If you have issues with Code I've provided, I appreciate your feedback.
    In the event Code provided resolves your issue, please mark your Thread as SOLVED.
    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

    ...enjoy -funny parrots-

  5. #5
    Forum Contributor
    Join Date
    02-01-2011
    Location
    london, england
    MS-Off Ver
    Excel 2016
    Posts
    179

    Re: Macro to send email upon certain date trigger

    Hi John,

    thanks for the reply, and yes, it does help, is there any way to make it so that the event occurs as you open the workbook? - and i need the email to send automatically? can this be done?

  6. #6
    Valued Forum Contributor john55's Avatar
    Join Date
    10-23-2010
    Location
    Europe
    MS-Off Ver
    Excel for Microsoft 365
    Posts
    2,060

    Re: Macro to send email upon certain date trigger

    yeap, copy the whole code and paste it in Thisworkbook (have a look in the left side and click on Thisworkbook and then in the right side select Workbook
    something like this...
    Private Sub Workbook_Open()
    Dim ce As Range, i As Long
        Dim OutApp As Object
        Dim OutMail As Object
        Dim strto As String, strcc As String, strbcc As String
        Dim strsub As String, strbody As String
    Dim MyName As String
    
        MyName = ThisWorkbook.Name
    
        For i = 2 To Sheets("Sheet1").Range("a65536").End(xlUp).Row
            If Cells(i, 1).Value <= Date And Cells(i, 2) = "" Then
                Set OutApp = CreateObject("Outlook.Application")
                OutApp.Session.Logon
                Set OutMail = OutApp.CreateItem(0)
            
                With Sheets("Sheet1")
                    strto = .Cells(i, 3).Value 'column O
                    strcc = "" '.Cells(i, 4).Value
                    strbcc = ""
                    strsub = MyName
                    strbody = "Hi there," & "pls see" & " " & MyName 'vbNewLine & vbNewLine & _
                        .Cells(i, 2).Value & " " & _
                        "needs an updated" & " " & .Cells(i, 4).Value & " " & _
                        "because it expires on" & " " & .Cells(i, 11).Value & "." & _
                        vbCrLf & vbCrLf & "Thank you."
                End With
        
                With OutMail
                    .To = strto
                    .CC = strcc
                    .BCC = strbcc
                    .Subject = strsub
                    .Body = strbody
                    '.Send
                    .display
                    Cells(i, 1).Select
         With Selection.Font
            .Color = -16776961
            .TintAndShade = 0
        End With
                End With
        
                Set OutMail = Nothing
                Set OutApp = Nothing
            End If
      
        Next i
    End Sub

  7. #7
    Forum Contributor
    Join Date
    02-01-2011
    Location
    london, england
    MS-Off Ver
    Excel 2016
    Posts
    179

    Re: Macro to send email upon certain date trigger

    Thanks for this John.

    It's perfect, apart from the fact the email doesn't automatically send?

  8. #8
    Valued Forum Contributor john55's Avatar
    Join Date
    10-23-2010
    Location
    Europe
    MS-Off Ver
    Excel for Microsoft 365
    Posts
    2,060

    Re: Macro to send email upon certain date trigger

    replace
    .display
    with
    .send

  9. #9
    Forum Contributor
    Join Date
    02-01-2011
    Location
    london, england
    MS-Off Ver
    Excel 2016
    Posts
    179

    Re: Macro to send email upon certain date trigger

    this works perfectly on the workbook you sent John, i just can't get it to work in my workbook! all i'm changing is the fact i'm using column's L and M instead of A and B...

    so i amended
    HTML Code: 
    to
    HTML Code: 
    column M is blank yet it's not working? conditional fomatting in column M wouldn't affect it would it?

  10. #10
    Valued Forum Contributor john55's Avatar
    Join Date
    10-23-2010
    Location
    Europe
    MS-Off Ver
    Excel for Microsoft 365
    Posts
    2,060

    Re: Macro to send email upon certain date trigger

    have a look at code and replace what is reffering to column A B,C
    here 1 is for col A, 2 is for col B
    '
    If Cells(i, 1).Value <= Date And Cells(i, 2) = "" Then
    '
    here 3 is for col C (please ignor the text in red)
    '
     strto = .Cells(i, 3).Value 'column O
    '

  11. #11
    Forum Contributor
    Join Date
    02-01-2011
    Location
    london, england
    MS-Off Ver
    Excel 2016
    Posts
    179

    Re: Macro to send email upon certain date trigger

    hi john,

    i've replaced 1, with 12 (for col L), 2 with 13 and i've put the email address in column N (for which i've used 14)

    still no luck.

    HTML Code: 

  12. #12
    Valued Forum Contributor john55's Avatar
    Join Date
    10-23-2010
    Location
    Europe
    MS-Off Ver
    Excel for Microsoft 365
    Posts
    2,060

    Re: Macro to send email upon certain date trigger

    and this one for yr date, I mean L as you said...
    '
    For i = 2 To Sheets("Sheet1").Range("a65536").End(xlUp).Row
    '

  13. #13
    Forum Contributor
    Join Date
    02-01-2011
    Location
    london, england
    MS-Off Ver
    Excel 2016
    Posts
    179

    Re: Macro to send email upon certain date trigger

    yes, i've changed this one as well and still not working !!

    i wish i could upload the workbook but work restrictions won't let me!!!

  14. #14
    Valued Forum Contributor john55's Avatar
    Join Date
    10-23-2010
    Location
    Europe
    MS-Off Ver
    Excel for Microsoft 365
    Posts
    2,060

    Re: Macro to send email upon certain date trigger

    k, I try it but tell me what are your columns used, for date, for empty cell, for email address!
    edit:
    hope these are yr colums
    Dim ce As Range, i As Long
        Dim OutApp As Object
        Dim OutMail As Object
        Dim strto As String, strcc As String, strbcc As String
        Dim strsub As String, strbody As String
    Dim MyName As String
    
        MyName = ThisWorkbook.Name
    
        For i = 2 To Sheets("Sheet1").Range("l65536").End(xlUp).Row
            If Cells(i, 12).Value <= Date And Cells(i, 13) = "" Then
                Set OutApp = CreateObject("Outlook.Application")
                OutApp.Session.Logon
                Set OutMail = OutApp.CreateItem(0)
            
                With Sheets("Sheet1")
                    strto = .Cells(i, 14).Value 'column O
                    strcc = "" '.Cells(i, 4).Value
                    strbcc = ""
                    strsub = MyName
                    strbody = "Hi there," & "pls see" & " " & MyName 'vbNewLine & vbNewLine & _
                        .Cells(i, 2).Value & " " & _
                        "needs an updated" & " " & .Cells(i, 4).Value & " " & _
                        "because it expires on" & " " & .Cells(i, 11).Value & "." & _
                        vbCrLf & vbCrLf & "Thank you."
                End With
        
                With OutMail
                    .To = strto
                    .CC = strcc
                    .BCC = strbcc
                    .Subject = strsub
                    .Body = strbody
                    '.Send
                    .display
                    Cells(i, 12).Select
         With Selection.Font
            .Color = -16776961
            .TintAndShade = 0
        End With
                End With
        
                Set OutMail = Nothing
                Set OutApp = Nothing
            End If
      
        Next i
    Last edited by john55; 01-14-2013 at 08:54 AM.

  15. #15
    Forum Contributor
    Join Date
    02-01-2011
    Location
    london, england
    MS-Off Ver
    Excel 2016
    Posts
    179

    Re: Macro to send email upon certain date trigger

    I've got it working John! Thank you so much! however, i don't think i set out my requirements fully - even if the whole column is blank, i only want 1 email sent, currently because the whole column of M is blank it tries to send an email for each row.

    does this make sense?

  16. #16
    Valued Forum Contributor john55's Avatar
    Join Date
    10-23-2010
    Location
    Europe
    MS-Off Ver
    Excel for Microsoft 365
    Posts
    2,060

    Re: Macro to send email upon certain date trigger

    if your column M is blank then
    '
     If Cells(i, 12).Value <= Date Then
    '

  17. #17
    Forum Contributor
    Join Date
    02-01-2011
    Location
    london, england
    MS-Off Ver
    Excel 2016
    Posts
    179

    Re: Macro to send email upon certain date trigger

    it keeps sending 1 email for each row, i only want 1 email sent total - not per row.

  18. #18
    Valued Forum Contributor john55's Avatar
    Join Date
    10-23-2010
    Location
    Europe
    MS-Off Ver
    Excel for Microsoft 365
    Posts
    2,060

    Re: Macro to send email upon certain date trigger

    try this, C2 is yr cell having the email address
    '
    ' With Sheets("Sheet1")
                    strto =[c2]
                    strcc = ""
                    strbcc = ""
    '
    or
     With Sheets("Sheet1")
                    strto ="kkk@yahoo.com"
                    strcc = ""
                    strbcc = ""
    '

  19. #19
    Forum Contributor
    Join Date
    02-01-2011
    Location
    london, england
    MS-Off Ver
    Excel 2016
    Posts
    179

    Re: Macro to send email upon certain date trigger

    not working i'm afraid, won't stop sending emails...

    Private Sub Workbook_Open()
    Dim ce As Range, i As Long
        Dim OutApp As Object
        Dim OutMail As Object
        Dim strto As String, strcc As String, strbcc As String
        Dim strsub As String, strbody As String
    Dim MyName As String
    
        MyName = ThisWorkbook.Name
    
        For i = 13 To Sheets("Sheet1").Range("l65536").End(xlUp).Row
            If Cells(i, 12).Value <= Date Then
                Set OutApp = CreateObject("Outlook.Application")
                OutApp.Session.Logon
                Set OutMail = OutApp.CreateItem(0)
            
                With Sheets("Sheet1")
                    strto = "karl.cassidy@argos.co.uk"
                    strcc = ""
                    strbcc = ""
                    strsub = MyName
                    strbody = "Hi Sarah," & "This range is either late for handing over, or the PIC hasn't populated a date in CT HO column" & " " & MyName 'vbNewLine & vbNewLine & _
    
                End With
        
                With OutMail
                    .To = strto
                    .CC = strcc
                    .BCC = strbcc
                    .Subject = strsub
                    .Body = strbody
                    .Send
                    Cells(i, 12).Select
         With Selection.Font
            .Color = -16776961
            .TintAndShade = 0
        End With
                End With
        
                Set OutMail = Nothing
                Set OutApp = Nothing
            End If
      
        Next i
    End Sub

  20. #20
    Valued Forum Contributor john55's Avatar
    Join Date
    10-23-2010
    Location
    Europe
    MS-Off Ver
    Excel for Microsoft 365
    Posts
    2,060

    Re: Macro to send email upon certain date trigger

    I am sorry, maybe someone else can help you!

  21. #21
    Forum Contributor
    Join Date
    02-01-2011
    Location
    london, england
    MS-Off Ver
    Excel 2016
    Posts
    179

    Re: Macro to send email upon certain date trigger

    thanks for trying John!

    can anyone else help?! If M2 is blank and the date in L2 has passed, i need to send an email.

  22. #22
    Valued Forum Contributor john55's Avatar
    Join Date
    10-23-2010
    Location
    Europe
    MS-Off Ver
    Excel for Microsoft 365
    Posts
    2,060

    Re: Macro to send email upon certain date trigger

    Dim ce As Range, i As Long
        Dim OutApp As Object
        Dim OutMail As Object
        Dim strto As String, strcc As String, strbcc As String
        Dim strsub As String, strbody As String
    Dim MyName As String
    
        MyName = ThisWorkbook.Name
    
        
            If [l2] <= Date And [m2] = "" Then
                Set OutApp = CreateObject("Outlook.Application")
                OutApp.Session.Logon
                Set OutMail = OutApp.CreateItem(0)
            
                With Sheets("Sheet1")
                    strto = "karl.cassidy@argos.co.uk"
                    strcc = "" '.Cells(i, 4).Value
                    strbcc = ""
                    strsub = MyName
                    strbody = "Hi there," & "pls see" & " " & MyName 'vbNewLine & vbNewLine & _
                        .Cells(i, 2).Value & " " & _
                        "needs an updated" & " " & .Cells(i, 4).Value & " " & _
                        "because it expires on" & " " & .Cells(i, 11).Value & "." & _
                        vbCrLf & vbCrLf & "Thank you."
                End With
        
                With OutMail
                    .To = strto
                    .CC = strcc
                    .BCC = strbcc
                    .Subject = strsub
                    .Body = strbody
                    '.Send
                    .display
                   
        End With
               
        
                Set OutMail = Nothing
                Set OutApp = Nothing
            End If

+ 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