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
|
Public Sub CreateEmail( _
Recipient As String, _
Subject As String, _
Body As String, _
Optional Attach As Variant)
' --------------------------
Dim I As Integer
Dim oEmail As Outlook.MailItem
Dim appOutLook As Outlook.Application
' Créer un nouvel item mail
Set appOutLook = New Outlook.Application
Set oEmail = appOutLook.CreateItem(olMailItem)
' Les paramètres
oEmail.To = Recipient
oEmail.Subject = Subject
oEmail.Body = Body
oEmail.Display
If Not IsMissing(Attach) Then
If TypeName(Attach) = "String" Then
' S'il y a des pièces jointes
oEmail.Attachments.Add Attach
Else
For I = 0 To UBound(Attach) - 1
oEmail.Attachments.Add Attach(I)
Next
End If
End If
' Envoie le message
' oEmail.Send
' Détruit les références aux objets
Set oEmail = Nothing
Set appOutLook = Nothing
End Sub |
Partager