Hi the code below sends an email every time the wb is opened if the due date is today or overdue to the email at the bottom of the code
how can i send the same email to anther one or two emails ? could it pick the emails up from the sheet instead of been in the code ???
any help please.
The file is too big to post but i have attached a dropbox link
https://www.dropbox.com/s/ph60yu46kl...nspection.xlsm
Code:
Private Sub Workbook_Open()
Dim rng As Range
Dim c As Variant
Dim ddiff As Long
Dim mdiff As Long
Dim fso As Object
Dim oOutlook As Object
Dim oMail As Object
Dim body As String
' Set the range of PPE dates to check
Set rng = Range("F7:F" & Range("F" & Rows.Count).End(xlUp).Row - 1)
' Set the initial email body. We will use this to check if we have issues later.
body = "The Following items are Due or Overdue Inspection" & ": " & Chr(9) & Chr(9) & Chr(9) & vbCrLf & vbCrLf & vbCrLf
For Each c In rng
' If each value in the range is a date, then do a check for months and days.
If IsDate(c.Value) Then
ddiff = DateDiff("d", Now(), c.Value)
mdiff = DateDiff("m", Now(), c.Value)
' If greater than 1 month away, only populate the cell, do not add to the email
' body. You many want to change this.
If ddiff > 0 Then
c.Offset(0, 4).Value = ddiff & " Days from now"
Else
' Else, if we have less than one month, use days as the indicator, and
' increment the email body.
If ddiff > 1 Then
c.Offset(0, 4).Value = ddiff & " days from now"
body = body & c.Offset(0, -1) & ": " & Chr(9) & c.Offset(0, -4) & Chr(9) & Chr(9) & Chr(9) & ddiff & " days from now" & vbCrLf
Else
If ddiff = 0 Then
c.Offset(0, 4).Value = "due today"
body = body & c.Offset(0, -1) & ": " & Chr(9) & Chr(9) & Chr(9) & c.Offset(0, -4) & ": " & Chr(9) & Chr(9) & Chr(9) & c.Offset(0, -3) & ": " & Chr(9) & Chr(9) & Chr(9) & " due today" & ": " & vbCrLf
Else
c.Offset(0, 4).Value = ddiff * -1 & " days overdue"
body = body & c.Offset(0, -1) & ": " & Chr(9) & Chr(9) & Chr(9) & Chr(9) & Chr(9) & c.Offset(0, -4) & ": " & Chr(9) & Chr(9) & Chr(9) & Chr(9) & c.Offset(0, -3) & ": " & Chr(9) & Chr(9) & Chr(9) & Chr(9) & ddiff * -1 & " days overdue" & ": " & vbCrLf
End If
End If
End If
End If
Next c
' If there is one we need to know about, send the email
If Len(body & "") > 0 Then
Set oOutlook = CreateObject("Outlook.Application")
Set oMail = oOutlook.createitem(0)
With oMail
.To = "peter.renton@northside.co.uk"
.Subject = "PPE dates"
.body = body
.send
End With
End If
End Sub
Bookmarks