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
| Sub Envoi_Email_base()
Dim OutApp As Object
Dim OutMail As Object
Set OutApp = CreateObject("Outlook.Application") 'Lance une session Microsoft Outlook'
Set OutMail = OutApp.CreateItem(0) 'Crée un nouveau message'
On Error Resume Next
'Si (lorsque) une erreur d'exécution se produit, VBA passe à l'instruction suivante celle ayant causé l'erreur'
With OutMail
.To = " " 'Destinataire du message'
.CC = " " 'En copie du message'
.BCC = ""
.Subject = " " 'Objet du message'
'Corps du message'
.Body = "Bonjour," _
& Chr(13) & " " _
& Chr(13) & "." & Chr(13) _
& Chr(13) & " " _
& "Cordialement."
.Attachments.Add ThisWorkbook.Path & "\" & ThisWorkbook.Name 'Pièces jointes du message : sur fichier ouvert'
.send 'Envoi du message'
End With
'ObjOutlook.Quit 'Quitte l'application Outlook'
Set objMail = Nothing
Set ObjOutlook = Nothing
On Error GoTo 0 'Désactive toute gestion d'erreur par une ou l'autre forme de On error"
Set OutMail = Nothing 'Réinitialise l'objet'
Set OutApp = Nothing 'Réinitialise l'objet'
End Sub |
Partager