Private Sub Envoyer_Click()
CreateEmail CStr(Me.Dest), CStr(Me.Sujet), CStr(Me.Msg)
End Sub
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
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