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 65 66 67 68 69 70
| Option Explicit
'Envoi du mail
Public Sub EnvoiMail()
Dim myOlApp As New Outlook.Application
Dim myOlIte As MailItem
Set myOlApp = New Outlook.Application
Set myOlIte = myOlApp.CreateItem(olMailItem)
With myOlIte
.To = ListeMailEnvoi
.Subject = "Objet du mail"
.Body = "Corps du texte"
'.Attachments.Add ""
.Send 'Envoi
End With
End Sub
'Création de la liste d'envoi
Public Function ListeMailEnvoi() As String
Dim strPrenom As String, strNom As String, strAdresse As String
Dim tabMail() As Variant
Dim tabEnvoi As Collection
Dim strEnvoi As String
Dim lngLigne As Long
Dim rngC As Range
Dim i As Integer
With Worksheets("Feuil1")
Set tabEnvoi = New Collection
'Liste des adresses mail
tabMail = Array("eric.martab@hotmail.fr", "christian.gillou@hotmail.fr")
lngLigne = .Range("J" & .Rows.Count).End(xlUp).Row
For Each rngC In .Range(.[J1], .Cells(lngLigne, 10))
If rngC.Value <> "" Then
strPrenom = LCase(Split(rngC.Value, " ")(0))
strNom = LCase(Split(rngC.Value, " ")(1))
strAdresse = strPrenom & "." & strNom & "@hotmail.fr"
If IsInArray(strAdresse, tabMail) = True Then
On Error Resume Next
tabEnvoi.Add strAdresse, strAdresse
On Error GoTo 0
End If
End If
Next rngC
End With
'Création de la liste d'envoi
For i = 1 To tabEnvoi.Count
ListeMailEnvoi = ListeMailEnvoi & tabEnvoi.Item(i) & "; "
Next i
End Function
'Fonction renvoyant "TRUE" si l'élement appartient au tableau passé en paramètre
Public Function IsInArray(FindValue As Variant, arrSearch As Variant) As Boolean
If Not IsArray(arrSearch) Then Exit Function
IsInArray = InStr(1, vbNullChar & Join(arrSearch, _
vbNullChar) & vbNullChar, vbNullChar & FindValue & _
vbNullChar) > 0
End Function |
Partager