Code to automatically send an email a week before date with a message.

Dazzawm

Well-known Member
Joined
Jan 24, 2011
Messages
3,783
Office Version
  1. 365
Platform
  1. Windows
I have a sheet as set out below. Is there a way or a code that will automatically send an email a week before the date in column B with a message of my choice?

Thanks.

Excel 2010
AB
john@gmail.com
eric@hotmail.com
daz@hotmail.co.uk

<colgroup><col style="width: 25pxpx" https:="" www.mrexcel.com="" forum="" usertag.php?do="list&action=hash&hash=DAE7F5"" target="_blank"></colgroup><colgroup><col><col></colgroup><thead>
</thead><tbody>
[TD="align: center"]2[/TD]

[TD="align: right"]25/07/2019[/TD]

[TD="align: center"]3[/TD]

[TD="align: right"]15/08/2019[/TD]

[TD="align: center"]4[/TD]

[TD="align: right"]10/10/2019[/TD]

</tbody>
Sheet1
 
Last edited:

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Any ideas anyone please? Or even if anyone knows a program that may do the same thing.
 
Upvote 0
.
This example auto-sends an email on the date specified in Col A, when the workbook is opened :

Code:
Option Explicit
Sub eMail()
Dim lRow As Integer
Dim i As Integer
Dim toDate As Date
Dim toList As String
Dim eSubject As String
Dim eBody As String
Dim OutApp
Dim OutMail


With Application
    .ScreenUpdating = False
    .EnableEvents = False
    .DisplayAlerts = False
End With


Sheets(1).Select
lRow = Cells(Rows.Count, 1).End(xlUp).Row


For i = 2 To lRow
toDate = Sheets("Sheet1").Cells(i, 1)


If toDate < Date Then: Exit Sub


  If Left(Cells(i, 5), 4) <> "Mail" And toDate = Date Then
  
             Set OutApp = CreateObject("Outlook.Application")
             Set OutMail = OutApp.CreateItem(0)
        
                toList = Cells(i, 2)    'gets the recipient from col B
                eSubject = Cells(i, 3)  'gets subject from col C
                eBody = Cells(i, 4)     'gets body of email from col D
                
                'enter email body here
                
                On Error Resume Next
                With OutMail
                .To = toList
                .CC = ""
                .BCC = ""
                .Subject = eSubject
                .Body = eBody
                .bodyformat = 1
                .Display   ' ********* Creates draft emails. Comment this out when you are ready
                '.Send     '********** UN-comment this when you  are ready to go live
                End With
         
            On Error GoTo 0
            Set OutMail = Nothing
            Set OutApp = Nothing
         Cells(i, 5) = "Mail Sent " & Date + Time 'Marks the row as "email sent in Column C"
             
    End If
Next i
ActiveWorkbook.Save


With Application
    .ScreenUpdating = True
    .EnableEvents = True
    .DisplayAlerts = True
End With
MsgBox "All emails have been sent. ", vbInformation, "Email Notice "


End Sub


Sub sbInsertingRows()
    'Inserting a Row at at Row 2
    Range("A2").EntireRow.Insert
End Sub

Download workbook : https://www.amazon.com/clouddrive/share/F7okMA0vsWpFtcN4uIe4DnPd7HJBuBU2JSRCaqp3Iow
 
Upvote 0
I see it uses Microsoft Outlook but I don't use that. Mine is the Windows 10 mail app.
 
Upvote 0
Doesn't your version of Office have Outlook ?

If not, you can download Outlook separately.
 
Upvote 0
So it wont work with the windows 10 email app? As the email account I want it sent from is a gmail
 
Last edited:
Upvote 0
Ok I have managed to set up my gmail in Microsoft Outlook. When I run your 'send' code it opens up the email but doesn't automatically send?
 
Upvote 0
.
Note the comments after .Send and .Display
 
Upvote 0

Forum statistics

Threads
1,223,681
Messages
6,173,816
Members
452,535
Latest member
berdex

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top