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
| Sub Mail(Sujet As String, Message As String, Destinataire As String, Optional Compte 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
If Compte <> "" Then .SentOnBehalfOfName = Compte
.To = Destinataire
.CC = DestinataireCopy
.BCC = DestinataireCopyCacher
.Subject = Sujet
.BodyFormat = 2
.HTMLBody = Message
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
Sub Test()
Mail "Sujet", "Message", "Destinataire@gmail.com", Compte:="noreplay@gmail.com", Pj:="C:\MyTest\Classeur1.xlsm;C:\MyTest\Classeur11.xlsm", DestinataireCopyCacher:="DestinataireCopyCacher@gmail.com"
Mail "Sujet", "Message", "Destinataire@gmail.com", Pj:="C:\MyTest\Classeur1.xlsm;C:\MyTest\Classeur11.xlsm", DestinataireCopy:="DestinataireCopy.com"
Mail "Sujet", "Message", "Destinataire@gmail.com", DestinataireCopy:="DestinataireCopy.com", DestinataireCopyCacher:="DestinataireCopyCacher@gmail.com"
Mail "Sujet", "Message", "Destinataire@gmail.com", DestinataireCopyCacher:="DestinataireCopyCacher@gmail.com"
Mail "Sujet", "Message", "Destinataire@gmail.com"
End Sub |
Partager