Sub Envoi_PDF()
Dim messageHTML
On Error GoTo errorHandler
Sheets("Feuil9").ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
ActiveWorkbook.Path & "\" & "Feuil9.pdf"
Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "Relevé horaire"
objMessage.From = "bobo@free.fr" 'pas obligatoire
objMessage.To = "coco@free.fr" 'obligatoire
objMessage.TextBody = "Bonjour," & vbCrLf & "Veuillez trouver en piéce jointe votre relevé d'heures" & vbCrLf & "excellente journée"
piece_jointe = ActiveWorkbook.Path & "\" & "Feuil9.pdf"
messageHTML = "Ceci est un message en HTML"
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.free.fr"
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objMessage.Configuration.Fields.Update
objMessage.AddAttachment (piece_jointe)
objMessage.Send
MsgBox "Le mail a été bien envoyé !"
Kill ActiveWorkbook.Path & "\" & "Feuil9.pdf"
' ATTENTION, renommer le chemin pour la sauvegarde
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"C:\Users\ARL\Desktop\TIME_CONTROL\MACRO_TIME_CONTROL\WORK_" & Range("C1").Text & ".pdf" _
, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=False
Exit Sub
errorHandler:
MsgBox Err.Description
End Sub