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
| Sub test()
MsgBox Mail("toi@free.fr", "lui.free.fr", "lesautre.free.fr", "le sujet est", "bla bla bla...", "c:\doc1.xls;c:\doc2.xls")
End Sub
Function Mail(Destinataire As String, Optional DestinataireCopy As String, Optional DestinataireCopyCaché As String, Optional Subject As String, Optional Body As String, Optional Document As String) As Boolean
On Error GoTo Erreur
Dim ObjApp As Object
Set ObjApp = CreateObject("Outlook.Application")
Dim ObjMail As Object
Set ObjMail = ObjApp.CreateItem(olMailItem)
Set ObjAttachement = ObjMail.Attachments
ObjMail.To = Destinataire
ObjMail.CC = DestinataireCopy
ObjMail.BCC = DestinataireCopyCaché
ObjMail.Subject = Subject
ObjMail.Body = Body
If Document <> "" Then
d = Split(Document & ";", ";")
For i = 0 To UBound(t) - 1
If Trim("" & d(i)) <> "" Then ObjAttachement.Add Trim("" & d(i))
Next
' ObjMail.Display
Mail = True
ObjMail.Send ' envoi du message
Exit Function
Erreur:
Mail = False
MsgBox Error
End Function |
Partager