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 52 53 54 55 56 57 58 59 60 61 62 63 64
| Private OL_App As Object
Private OL_Mail As Object
Private sSubject As String, sBody As String
Sub SendDocuments()
Dim i As Long
Dim tabContactNames As Variant, tabContactEmails As Variant, tabFNames As Variant
Application.ScreenUpdating = False
' Ouverture d'outlook
On Error Resume Next
Set OL_App = GetObject(, "Outlook.Application")
If OL_App Is Nothing Then
Set OL_App = CreateObject("Outlook.Application")
End If
On Error GoTo 0
' Objet du mail + corps du mail
sSubject = Range("D3").Value
sBody = Range("B8").Value
' Lecture de la liste des contacts
tabContactNames = Range("C25:C34").Value
tabContactEmails = Range("B25:B34").Value
tabFNames = Range("E25:E34").Value
' Générer les emails
For i = 1 To UBound(tabContactNames, 1)
If tabContactNames(i, 1) <> vbNullString Then
Call CreateNewMessage(tabContactNames(i, 1), tabContactEmails(i, 1), tabFNames(i, 1))
End If
Next i
MsgBox "Mail générés"
Set OL_App = Nothing
Set OL_Mail = Nothing
Application.ScreenUpdating = True
End Sub
Private Sub CreateNewMessage(strContactName, strContactTo, strFName)
Set OL_Mail = OL_App.CreateItem(0)
With OL_Mail
.To = strContactTo
.CC = "exemple@domain.com"
'.BCC = "exemple@domain.com"
.Subject = sSubject
.Body = sBody
.BodyFormat = 2 'Format : 0=inder; 1=plain text; 2= HTML; 3=rich text
.Importance = 2 'Importance : 0=low; 1=normal; 2= high
.Sensitivity = 3 'Confidentiality : 0=normal; 1=personal; 2=private; 3=confidential
.Attachments.Add (strFName)
' Display or send the message
.Display
'.Send
End With
Set OL_Mail = Nothing
End Sub |
Partager