Configuration EMAIL VBA
bONJOUR
je voulais savoir si je pourrais utiliser le .body d'une maniere multiple parceque je fais de l"automatisation des emails personalisees avec des conditions y ' en a des cas ou je dois utliser le body 2 fois ou 3 fois
j'apprecie beacoup votre aide
vous trouveriez le code en dessous
Sub Create_Mail_From_List()
Dim OutApp As Object
Dim OutMail As Object
Dim cell As Range
Application.ScreenUpdating = False
Set OutApp = CreateObject("Outlook.Application")
On Error GoTo cleanup
For Each cell In Columns("C").Cells.SpecialCells(xlCellTypeConstants)
If cell.Value Like "?*@?*.?*" And _
LCase(Cells(cell.Row, "I").Value) = "dnm" Then
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = cell.Value
.Subject = "Reponse a l'examen "
If LCase(Cells(cell.Row, "E").Value) = "dnm" Then
.Body = Sheets("lien").Range("B9").Value
'.Body = "Dear " & Cells(cell.Row, "A").Value _
& vbNewLine & vbNewLine & _
" " & _
" "
End If
If LCase(Cells(cell.Row, "F").Value) = "dnm" Then
.Body = Sheets("lien").Range("B10").Value
End If
'.Attachments.Add ("")
.Display 'Or use Display.
End With
On Error GoTo 0
Set OutMail = Nothing
End If
Next cell
cleanup:
Set OutApp = Nothing
Application.ScreenUpdating = True
End Sub
Sub Create_Mail_From_List()
Dim OutApp As Object
Dim OutMail As Object
Dim cell As Range
Application.ScreenUpdating = False
Set OutApp = CreateObject("Outlook.Application")
On Error GoTo cleanup
For Each cell In Columns("C").Cells.SpecialCells(xlCellTypeConstants)
If cell.Value Like "?*@?*.?*" And _
LCase(Cells(cell.Row, "I").Value) = "dnm" Then
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = cell.Value
.Subject = "Reponse a l'examen "
If LCase(Cells(cell.Row, "E").Value) = "dnm" Then
.Body = Sheets("lien").Range("B9").Value
'.Body = "Dear " & Cells(cell.Row, "A").Value _
& vbNewLine & vbNewLine & _
" " & _
" "
End If
If LCase(Cells(cell.Row, "F").Value) = "dnm" Then
.Body = Sheets("lien").Range("B10").Value
End If
'.Attachments.Add ("")
.Display 'Or use Display.
End With
On Error GoTo 0
Set OutMail = Nothing
End If
Next cell
cleanup:
Set OutApp = Nothing
Application.ScreenUpdating = True
End Sub
Bonjour,
utilise une variable intermédiaire par exemple bodymsg
bodymsg="partie 1"
bodymsg=bodymsg & "partie 2"
if condition1 then
bodymsg=bodymsg & "partie 3"
end if
.body=bodymsg
merci pour votre initiative
et je declare la variable comme quoi ? dim ?
j'ai essaye ca mais lorsque jai deux conditions vraies je recois seulement une
If LCase(Cells(cell.Row, "E").Value) = "dnm" Then
bodymessage = Sheets("lien").Range("B9").Value
End If
If LCase(Cells(cell.Row, "F").Value) = "dnm" Then
bodymessage = Sheets("lien").Range("B10").Value
End If
If LCase(Cells(cell.Row, "G").Value) = "dnm" Then
bodymessage = vbNewLine & Sheets("lien").Range("B11").Value
End If
If LCase(Cells(cell.Row, "H").Value) = "dnm" Then
bodymessage = Sheets("lien").Range("B12").Value
End If
.Body = bodymessage
Bonsoir,
essaie ainsi
dim bodymessage
If LCase(Cells(cell.Row, "E").Value) = "dnm" Then
bodymessage = Sheets("lien").Range("B9").Value
End If
If LCase(Cells(cell.Row, "F").Value) = "dnm" Then
bodymessage = bodymessage & ", " & Sheets("lien").Range("B10").Value
End If
If LCase(Cells(cell.Row, "G").Value) = "dnm" Then
bodymessage = bodymessage & vbNewLine & Sheets("lien").Range("B11").Value
End If
If LCase(Cells(cell.Row, "H").Value) = "dnm" Then
bodymessage = bodymessage & Sheets("lien").Range("B12").Value
End If
.Body = bodymessage