Option Explicit
Sub Envoi_Mail()
Dim StrBody As String, Chemin As String, Fichier As String, nom As String
Dim Sujet As String, feuille As String, depot As String, annee As String
Dim olApp As Object, derlig As Long, i As Integer, EnvoisA As String, olMail, Liste
With Sheets(1)
nom = .Range("A6").Value & ".xls" 'Nom de la feuille à envoyer
feuille = .Range("A7").Value
depot = .Range("A8").Value
annee = .Range("A9").Value
End With
Set olApp = CreateObject("Outlook.Application")
Set olMail = olApp.CreateItem(0)
Sujet = feuille & " " & depot & " : Compte-rendu " & annee
StrBody = "Bonjour Medames, Messieurs," & vbCrLf & vbCrLf & "Votre nouveau classeur en pièce jointe"
Chemin = ThisWorkbook.Path & "\" ' à modifier si nécessaire
Sheets(1).Copy
ActiveSheet.SaveAs Filename:=Chemin & nom, FileFormat:=xlExcel8
ActiveWorkbook.Close True
Fichier = Chemin & nom
With Sheets(2) 'Ici met toutes les adresses email
EnvoisA = .Range("a2") 'Envoyer à
derlig = .Range("a" & Rows.Count).End(xlUp).Row
For i = 3 To derlig
Liste = Liste & .Cells(i, 1).Value & ";" 'Copies cachées
Next i
End With
With olMail
.To = EnvoisA
.BCC = Liste
.Subject = Sujet
.Body = StrBody
.Attachments.Add Fichier
.Display 'Pour afficher avant envois
'.Send 'Pour envoyer
End With
Set olMail = Nothing
Set olApp = Nothing
End Sub