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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
| Option Explicit
Sub Commandbutton1_click()
On Error GoTo Erreur
If MsgBox("Souhaitez-vous envoyer le mail ?", vbYesNo, "Demande de confirmation pour l'envoi du mail") = vbYes Then
Dim Ouvriroutlook As Object
Dim OuvrirMessage As Object
Dim AdresseMail As String
Dim AdresseMAilIA As String
Dim SalariéSubject1 As String 'toutes ces variables sont les differents objet et message a inclure
Dim SalariéBody1 As String
Dim SalariéSubject2 As String
Dim SalariéBody2 As String
Dim SalariéSubject3 As String
Dim SalariéBody3 As String
Dim SalariéSubject4 As String
Dim SalariéBody4 As String
Dim SalariéSubject5 As String
Dim SalariéBody5 As String
Dim IndépendantSubject1 As String
Dim IndépendantBody1 As String
Dim IndépendantSubject2 As String
Dim IndépendantBody2 As String
Dim IndépendantSubject4 As String
Dim IndépendantBody4 As String
Dim IndépendantSubject5 As String
Dim IndépendantBody5 As String
Dim Statut As String
Dim Relance As String
Dim Returnreceipt As Boolean
Dim i As Integer, nbLignes As Long
Set Ouvriroutlook = CreateObject("Outlook.Application")
nbLignes = Cells(Rows.Count, "A").End(xlUp).Row
SalariéSubject1 = Worksheets("Annexe").Cells(2, 3)
SalariéBody1 = Worksheets("Annexe").Cells(2, 4)
SalariéSubject2 = Worksheets("Annexe").Cells(3, 3)
SalariéBody2 = Worksheets("Annexe").Cells(3, 4)
SalariéSubject3 = Worksheets("Annexe").Cells(4, 3)
SalariéBody3 = Worksheets("Annexe").Cells(4, 4)
SalariéSubject4 = Worksheets("Annexe").Cells(5, 3)
SalariéBody4 = Worksheets("Annexe").Cells(5, 4)
SalariéSubject5 = Worksheets("Annexe").Cells(6, 3)
SalariéBody5 = Worksheets("Annexe").Cells(6, 4)
IndépendantSubject1 = Worksheets("Annexe").Cells(7, 3)
IndépendantBody1 = Worksheets("Annexe").Cells(7, 4)
IndépendantSubject2 = Worksheets("Annexe").Cells(8, 3)
IndépendantBody2 = Worksheets("Annexe").Cells(8, 4)
IndépendantSubject4 = Worksheets("Annexe").Cells(10, 3)
IndépendantBody4 = Worksheets("Annexe").Cells(10, 4)
IndépendantSubject5 = Worksheets("Annexe").Cells(11, 3)
IndépendantBody5 = Worksheets("Annexe").Cells(11, 4)
For i = 5 To nbLignes
AdresseMail = Worksheets("Tableau").Cells(i, 3).Text
AdresseMAilIA = Worksheets("Tableau").Cells(i, 6)
Statut = Range("G" & i)
Relance = Range("H" & i)
If Statut = "Salarié" And Relance = "Démarrage" Then
Set OuvrirMessage = Ouvriroutlook.CreateItem(0)
With OuvrirMessage
.To = AdresseMail
.Subject = SalariéSubject1
.CC = AdresseMAilIA
.Body = SalariéBody1
.Attachments.Add ("C:\Book1.xls")
.display
' .Send
End With
Returnreceipt = True
ElseIf Statut = "Salarié" And Relance = "1ère Relance" Then
Set OuvrirMessage = Ouvriroutlook.CreateItem(0)
With OuvrirMessage
.To = AdresseMail
.Subject = SalariéSubject2
.CC = AdresseMAilIA
.Body = SalariéBody2
.Attachments.Add ("C:\Book1.xls")
.display
' .Send
End With
Returnreceipt = True
ElseIf Statut = "Salarié" And Relance = "2ème Relance" Then
Set OuvrirMessage = Ouvriroutlook.CreateItem(0)
With OuvrirMessage
.To = AdresseMail
.Subject = SalariéSubject3
.CC = AdresseMAilIA
.Body = SalariéBody3
.Attachments.Add ("C:\Book1.xls")
.display
' .Send
End With
Returnreceipt = True
ElseIf Statut = "Salarié" And Relance = "Changement mission" Then
Set OuvrirMessage = Ouvriroutlook.CreateItem(0)
With OuvrirMessage
.To = AdresseMail
.Subject = SalariéSubject4
.CC = AdresseMAilIA
.Body = SalariéBody4
.Attachments.Add ("C:\Book1.xls")
.display
' .Send
End With
Returnreceipt = True
ElseIf Statut = "Salarié" And Relance = "Changement mission relance" Then
Set OuvrirMessage = Ouvriroutlook.CreateItem(0)
With OuvrirMessage
.To = AdresseMail
.Subject = SalariéSubject5
.CC = AdresseMAilIA
.Body = SalariéBody5
.Attachments.Add ("C:\Book1.xls")
.display
' .Send
End With
End If
Set OuvrirMessage = Nothing
Next
MsgBox "Le mail a bien été envoyé à "
Else
MsgBox ("Les mails n'ont pas été envoyés")
End If
Exit Sub
Erreur:
MsgBox Err.Description
End Sub |