Sub Workbook_Open()
nbalert = 0
derlig = Sheets("Tableau suivi clients").Cells(Cells.Rows.Count, "A").End(xlUp).Row
For Each c In Sheets("Tableau suivi clients").Range("P2:p" & derlig)
ecart = c - Date
c.Interior.ColorIndex = -4142
If ecart <= 15 And c.Offset(0, 2) < 2 And c <> "" Then
Call envoi(c.Offset(0, -15) & " est définie dans " & ecart & " jours")
nbalert = nbalert + 1
c.Interior.Color = RGB(255, 0, 0)
End If
Next
End Sub
Sub envoi(mess)
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
With iConf.fields
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "xxxxxxxxx@gmail.com"
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "xxxxx"
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = 1
.Update
End With
With iMsg
Set .Configuration = iConf
.To = "xxxxxxxxxxxxxxxxxxxxxxx.com"
.CC = ""
.BCC = ""
.From = "xxxxxxxxxxxxxx@gmail.com"
.Subject = "Alert"
.textbody = mess
.Send
End With
End Sub