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
| Sub envoi()
Dim cel As Range, fc As String, admail As String
Dim responsable As String, messmail As String
responsable = "Toto"
'ci-dessous une feuille "adresses"
For Each cel In Sheets("adresses").Range("A2:a33") 'si les données (adresses mail et fichier à envoyer) sont en A et B
admail = cel.Value
fc = cel(1, 2).Value 'attention mettre chemin complet du fichier à envoyer
messmail = "Bonjour" & Chr(10) & "Ci-joint, le fichier" & Chr(10) & Chr(10) & responsable
'ci-dessous vérifier le chemin d'outlook
If Trim("" & admail) <> "" Then Mail "CHALETS A JOUR", messmail, admail, Pj:=fc
Next cel
End Sub
Sub Mail(Sujet As String, Message As String, Destinataire As String, Optional DestinataireCopy As String, Optional DestinataireCopyCacher As String, Optional Pj As String = "")
Set objOutlook = CreateObject("Outlook.application")
Set MailObj = objOutlook.CreateItem(olMailItem)
With MailObj
.To = Destinataire
.CC = DestinataireCopy
.BCC = DestinataireCopyCacher
.Subject = Sujet
.BodyFormat = 2
.HTMLBody = Replace(Messagec, Chr(10), "<br>")
If Trim("" & Pj) <> "" Then
p = Split(Pj & ";", ";")
For i = 0 To UBound(p)
If Trim("" & p(i)) <> "" Then .Attachments.Add Trim("" & p(i))
Next
End If
'.Display 'Can be .Send but prompts for user intervention before sending without 3rd party software like ClickYes
.Send
End With
End Sub |
Partager