+ Reply to Thread
Results 1 to 4 of 4

VBA for Email Reminders (Outlook)

Hybrid View

  1. #1
    Registered User
    Join Date
    06-20-2019
    Location
    Minnesota
    MS-Off Ver
    Office 2019
    Posts
    39

    VBA for Email Reminders (Outlook)

    Hello, I'm looking to use VBA to send emails, using Outlook, based upon specific dates. Below is an explanation of columns:

    A: License Name
    B: License Purchase Date
    C: License Expiration Date
    E: 3 Months Prior to Expiration Date
    F: 1 Week Prior to Expiration Date

    What I'm looking to do is have Excel send me an email 3 months before the license expires (including the license name from column a and the expiration date from column C), as well as another reminder 1 week prior to expiration. Any help would be greatly appreciate - thanks!

  2. #2
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,419

    Re: VBA for Email Reminders (Outlook)

    .
    Here are two examples you can review and edit to your needs :

    30 days out :

    Option Explicit
    
    Sub chkdate()
    Dim n As String
    Dim Today As Long
    
    n = Sheets("Sheet1").Range("A1").Value
    
    If n < (Now() + 30) Then
        'MsgBox "Time !"
        Send_Mail_From_Excel
    End If
    
    End Sub
    
    
    Sub Send_Mail_From_Excel()
        Dim OutlookApp As Object
        Dim OutlookMail As Object
     
        Set OutlookApp = CreateObject("Outlook.Application")
        Set OutlookMail = OutlookApp.CreateItem(0)
     
        'Send Mass Email Using Excel VBA Macro Code
        With OutlookMail
            .to = "youremail@some.com"
            .CC = ""
            .BCC = ""
            .Subject = "30 Day Check"
            .Body = "Time to check the date !"
            '.Send  ' or just put .Send to directly send the mail instead of display
            .Display
            
        End With
     
        Set OutlookMail = Nothing
        Set OutlookApp = Nothing
    End Sub


    X Days Ahead :

    Option Explicit
    
    Sub SndMail()
    Dim cll As Variant
    Dim duedays As String
    
        With Sheets("Sheet2")
            For Each cll In .Range("G6:G" & .Cells(.Rows.Count, 7).End(xlUp).Row)
                If cll.Value = Date + 30 And cll.Offset(, 7) = vbNullString Then
                    cll.Offset(, 7).Value = "X": duedays = 30
                    GoTo sendmail
                ElseIf cll.Value = Date + 15 And cll.Offset(, 8) = vbNullString Then
                    cll.Offset(, 8).Value = "X": duedays = 15
                    GoTo sendmail
                Else
                    GoTo continue
                End If
    sendmail:
                With CreateObject("Outlook.Application").CreateItem(0)
                    .To = cll.Offset(, 1).Value
                    .Subject = "Risk Assessments Due"
                    .Body = "Dear, " & vbNewLine & vbNewLine & _
                        cll.Offset(, -6).Value & " is due in " & duedays & " days." & vbNewLine & vbNewLine & _
                        "Please contact us to make an appointment." & vbNewLine & vbNewLine & _
                        "Service Agent : " & cll.Offset(, 2).Value
                        '.Attachments.Add ("C:\test.txt")
                    .Display '.Send
                End With
    continue:
            Next
        End With
    End Sub
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    06-20-2019
    Location
    Minnesota
    MS-Off Ver
    Office 2019
    Posts
    39

    Re: VBA for Email Reminders (Outlook)

    I copy and pasted your code into my VBA. I changed the reference from A1 to B2 for n as B2 is the first cell in which the expiration dates can be found. I'm looking for something to automatically run the macro for me without me having to open the workbook everyday and click on the macro in order for it to run.

  4. #4
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,419

    Re: VBA for Email Reminders (Outlook)

    .
    You will need to open the workbook in order for it to function as desired.

    In the VBE, in the ThisWorkbook module, you can select the Workbook_Open and place a call to the email macro there.

    Example :

    Option Explicit
    
    Private Sub Workbook_Open()
        SndMail
    End Sub

    Anytime you open the workbook, the macro will auto run.

+ 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. Seeking help on automatic email reminders
    By ReyBradford in forum Hello..Introduce yourself
    Replies: 1
    Last Post: 02-08-2019, 11:10 AM
  2. [SOLVED] Automatic email reminders based on different deadlines on Excel
    By yawwwn in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 08-27-2015, 02:41 AM
  3. Email Daily Reminders from Monthly Calendar
    By newbie4 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-23-2014, 12:48 PM
  4. Macro to send automated email reminders
    By Amber12 in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 02-13-2014, 11:22 AM
  5. Auto sending email reminders to clients from excel
    By HGV in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-27-2014, 11:33 AM
  6. Help with automated pop-up box and email reminders, and reminder list
    By dashcanon in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-09-2013, 09:28 PM
  7. [SOLVED] Expiry Reminders - Reminder email to relevant party for further ac
    By little_rascal in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-25-2006, 10:30 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