+ Reply to Thread
Results 1 to 5 of 5

I need excel to send out an email as a reminder that an expiration date is coming due.

Hybrid View

  1. #1
    Registered User
    Join Date
    08-01-2014
    Location
    Virginia
    MS-Off Ver
    2010
    Posts
    4

    I need excel to send out an email as a reminder that an expiration date is coming due.

    Can anyone help me with getting Excel to send an email in outlook as a reminder that a expiration date is coming due?
    I need to know a month in advance that a date in column F is coming due.
    Btw, I have zero experience with VBA but I am anxious to learn.
    Any help with this will be greatly appreciated.
    Thank you,
    Grim
    Attached Files Attached Files

  2. #2
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,125

    Re: I need excel to send out an email as a reminder that an expiration date is coming due.

    Here's an article about that. Post back if you have more questions.
    David
    (*) Reputation points appreciated.

  3. #3
    Registered User
    Join Date
    08-01-2014
    Location
    Virginia
    MS-Off Ver
    2010
    Posts
    4

    Re: I need excel to send out an email as a reminder that an expiration date is coming due.

    Thank for the reply.
    The article in the link you posted is very confusing. It appears that the only time the code in it will send an email as if/when you manually change the value in the target cell.
    I need an email sent 30 days prior to the due dates if column F (F3:F21) in the sample workbook in my original post.
    Any help you can provide will be greatly appreciated.
    Thank you,
    Grim

  4. #4
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,125

    Re: I need excel to send out an email as a reminder that an expiration date is coming due.

    OK, you got me.
    Sub Mail_Selection_Range_Outlook_Body()
    'For Tips see: http://www.rondebruin.nl/win/winmail/Outlook/tips.htm
    'Don't forget to copy the function RangetoHTML in the module.
    'Working in Excel 2000-2016
        Dim Rng As Range
        Dim RngStr As String
        Dim OutApp As Object
        Dim OutMail As Object
    
        Set Rng = Nothing
        On Error Resume Next
        'Only the visible cells in the selection
        'Set rng = Selection.SpecialCells(xlCellTypeVisible)
        'You can also use a fixed range if you want
        'Set rng = Sheets("YourSheet").Range("D4:D12").SpecialCells(xlCellTypeVisible)
        'On Error GoTo 0
    
    'Build a string representing the overdue equipment
    'Start with Title and header rows.
    RngStr = "A1:F2,"
    For Each Rng In Range("F3:F21") 'Look down column F.
        If Rng.Value <= Date - 30 Then
            'We found a date that is at least 30 days prior to today.
            RngStr = RngStr & Range("A" & Rng.Row & ":F" & Rng.Row).Address & ","
        End If
    Next
    'Debug.Print RngStr
        If Len(RngStr) = 0 Then
            MsgBox "The selection is not a range or the sheet is protected" & _
                   vbNewLine & "please correct and try again.", vbOKOnly
            Exit Sub
        Else
            'Strip off training comma
            RngStr = Left(RngStr, Len(RngStr) - 1)
            'Define Range using range string
            Set Rng = Range(RngStr)
            Rng.Select 'Used for visual feedback.
        End If
    
        With Application
            .EnableEvents = False
            .ScreenUpdating = False
        End With
    
        Set OutApp = CreateObject("Outlook.Application")
        Set OutMail = OutApp.CreateItem(0)
    
        On Error Resume Next
        With OutMail
            .To = "[email protected]"
            .CC = ""
            .BCC = ""
            .Subject = "Equipment < Today - 30"
            .HTMLBody = RangetoHTML(Rng)
            'Will pause for last edit.
            .Display
        End With
        On Error GoTo 0
    
        With Application
            .EnableEvents = True
            .ScreenUpdating = True
        End With
    
        Set OutMail = Nothing
        Set OutApp = Nothing
    End Sub
    
    
    Function RangetoHTML(Rng As Range)
    ' Changed by Ron de Bruin 28-Oct-2006
    ' Working in Office 2000-2016
        Dim fso As Object
        Dim ts As Object
        Dim TempFile As String
        Dim TempWB As Workbook
    
        TempFile = Environ$("temp") & "\" & Format(Now, "dd-mm-yy h-mm-ss") & ".htm"
    
        'Copy the range and create a new workbook to past the data in
        Rng.Copy
        Set TempWB = Workbooks.Add(1)
        With TempWB.Sheets(1)
            .Cells(1).PasteSpecial Paste:=8
            .Cells(1).PasteSpecial xlPasteValues, , False, False
            .Cells(1).PasteSpecial xlPasteFormats, , False, False
            .Cells(1).Select
            Application.CutCopyMode = False
            On Error Resume Next
            .DrawingObjects.Visible = True
            .DrawingObjects.Delete
            On Error GoTo 0
        End With
    
        'Publish the sheet to a htm file
        With TempWB.PublishObjects.Add( _
             SourceType:=xlSourceRange, _
             Filename:=TempFile, _
             Sheet:=TempWB.Sheets(1).Name, _
             Source:=TempWB.Sheets(1).UsedRange.Address, _
             HtmlType:=xlHtmlStatic)
            .Publish (True)
        End With
    
        'Read all data from the htm file into RangetoHTML
        Set fso = CreateObject("Scripting.FileSystemObject")
        Set ts = fso.GetFile(TempFile).OpenAsTextStream(1, -2)
        RangetoHTML = ts.readall
        ts.Close
        RangetoHTML = Replace(RangetoHTML, "align=center x:publishsource=", _
                              "align=left x:publishsource=")
    
        'Close TempWB
        TempWB.Close savechanges:=False
    
        'Delete the htm file we used in this function
        Kill TempFile
    
        Set ts = Nothing
        Set fso = Nothing
        Set TempWB = Nothing
    End Function
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    08-01-2014
    Location
    Virginia
    MS-Off Ver
    2010
    Posts
    4

    Re: I need excel to send out an email as a reminder that an expiration date is coming due.

    Thank you Tinbender.
    Works like a charm.
    R/
    Grim

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Use Hyperlink to send email 6 months before expiration date
    By mcivli65 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 10-28-2015, 01:24 PM
  2. Send email reminder based on due date while excel doc is closed
    By gnada in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-11-2015, 07:51 PM
  3. using excel to send reminder email using vb
    By Keith Gold in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-27-2015, 01:05 AM
  4. send reminder email from excel spreadsheet based on several next due columns
    By lisanoe in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-23-2013, 02:38 AM
  5. Replies: 5
    Last Post: 02-22-2013, 02:00 AM
  6. auto search for expiration date and send email to users
    By mingchu in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-08-2013, 06:07 PM
  7. Excel 2007 : Pop up reminder and send email from Excel 2007
    By excel_for_dummy in forum Excel General
    Replies: 1
    Last Post: 12-19-2011, 05:06 PM

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