Sub Envoi_Mail()
' On Error Resume Next
' Touche de raccourci du clavier : Ctrl+e
Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String
Dim PJ As String 'Piece-Jointe=OUI/NON
' Dim List_To As String, List_Cop As String
' ici je repère la dernière ligne vide pour la Collection des données
Dim List_To As String, List_Cop As String, rng As Range, t, tt
' UF_Attente.Show vbModeless
' ici je repère la dernière ligne vide pour la Collection des données
' ici- dessous début des lignes modifiées
With Worksheets("Mail")
Set rng = .Range(.Cells(2, "N"), .Cells(Rows.Count, "N").End(3))
If rng.Rows.Count > 2 Then
t = Application.Transpose(rng.Value): List_To = Join(t, ";")
tt = Application.Transpose(rng.Offset(, 1)): List_Cop = Join(tt, ";")
' pour tester le contenu des listes de mails
Else
MsgBox "Attention : Vous n'avez pas de destinataire !"
Exit Sub
End If
End With
' fin des lignes modifiées
' Set OutApp = CreateObject("Outlook.Application")
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
' contenu Message
'Application.Dialogs(xlDialogOpen).Show (chemin)
'Selection = fichier
With Worksheets("Mail")
PJ = .Range("M2")
Sujet = .Range("J3")
strbody = .Shapes("CorpsMessage").TextFrame.Characters.Text & vbTab 'str
End With
With OutMail
.To = List_To
.CC = List_Cop
.BCC = ""
.Subject = Sujet
.Body = strbody
' You can add a file like this
If UCase(PJ) = "OUI" Then
Dim fichier As Variant
fichier = Application.GetOpenFilename("Tous les fichiers (*.*),*.*")
.Attachments.Add (fichier) 'mettre ce que vous voulez
End If
.Display
' or use
.Send
End With
' attente envoi @Mail
' Application.Wait Application.Wait(Now + TimeValue("0:00:01"))
Set OutMail = Nothing
Set OutApp = Nothing
End Sub