1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
Const olMailItem As Long = 0
Sub EnvoiMail()
Dim olApp As Object, M As Object, c As Range
Dim dLig As Long, dCol As Long, Col As Long, Lig As Long
Dim Cel As Range
' Créer une instance Outlook
Set olApp = CreateObject("Outlook.application")
With Sheets("Feuil1")
dLig = .Range("A" & Rows.Count).End(xlUp).Row
dCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
For Lig = 3 To dLig
For Col = 2 To dCol - 2 Step 1
' Définir sur quelle cellule on travaille
Set Cel = .Cells(Lig, Col)
'
If IsDate(Cel) And Cel.Offset(, 1) = "Non" Then
If Cel - Date < 30 And Cel > Date Then
Set M = olApp.CreateItem(olMailItem)
M.Subject = "Echéance " & .Cells(1, Col) & " " & .Cells(Lig, 1)
M.Bcc = "Mailcopie@fr"
M.body = "Bonjour," & vbCrLf & vbCrLf & "La " & .Cells(1, Col) & " du " & .Cells(Lig, 1) & _
" arrive à échéance le " & Cel
M.Recipients.Add .Cells(Lig, dCol)
M.display
Cel.Offset(, 1) = "Oui"
End If
End If
Next Col
Next Lig
End With
End Sub |
Partager