Sub Ordre_de_mission()
Dim xSht As Worksheet
Dim xFileDlg As FileDialog
Dim xFolder As String
Dim xYesorNo As Integer
Dim xOutlookObj As Object
Dim xEmailObj As Object
Dim xUsedRng As Range
Set xSht = ActiveSheet
xFolder = ThisWorkbook.Path & Application.PathSeparator & Range("J3") & "_" & Range("K2") & "." & "pdf" '/ = mauvais charactère
'xFolder = ThisWorkbook.Path & PathSeparator & xSht.Name
MsgBox "Le fichier a été sauvegardé en PDF dans votre dossier" & vbCrLf & "Ordre de mission." & vbCrLf & vbCrLf & "FH"
Set xUsedRng = xSht.UsedRange
If Application.WorksheetFunction.CountA(xUsedRng.Cells) <> 0 Then
'Save as PDF file
xSht.ExportAsFixedFormat Type:=xlTypePDF, Filename:=xFolder, Quality:=xlQualityStandard
'Create Outlook email
Set xOutlookObj = CreateObject("Outlook.Application")
Set xEmailObj = xOutlookObj.CreateItem(0)
With xEmailObj
.Display
.To = Range("G1")
.CC = Range("H1")
.Display ' afficher le mail avant de l’envoyer sinon placer send pour envoyer
.Subject = ChrW(&HD83D) & ChrW(&HDE97) & " " & Range("G2") & " : " & ChrW(&HD83D) & ChrW(&HDCDD) & " " & Range("C21") & ", " & ChrW(&HD83D) & ChrW(&HDCC5) & " " & Format(Range("B11").Value, " dddd d mmmm yyyy, ") & ChrW(&H231A) & " " & Range("J18") & "."
.HTMLBody = "<font face=""Arial""><font size=""10px"">" & Range("I1") & vbCrLf & vbCrLf & Range("J1") & Range("K1") & "<br>" & "<br>" & Range("G3") _
& "<br>" & "<br>" & "<U>Objet :</U>" & vbCrLf & vbCrLf & "<font color=#305496>" & ChrW(&HD83D) & ChrW(&HDE97) & " " & Range("G2") & " : " & ChrW(&HD83D) & ChrW(&HDCDD) & " " & vbCrLf & Range("C21") & ", " & ChrW(&HD83D) & ChrW(&HDCC5) & Format(Range("B11").Value, " dddd d mmmm yyyy, ") & ChrW(&H231A) & " " & Range("J18") & ", " & ChrW(&H23F1) & ChrW(&HFE0F) & vbCrLf & vbCrLf & [text(E12,"[hh]:mm")] & "." & "</font>" & "<br>" & "<br>" & "Référence ordre de mission: " & vbCrLf & vbCrLf _
& "<font color=#305496>" & Range("H2") & "</font>" & "<br>" & "<br>" & Range("C6") & vbCrLf & vbCrLf & "<font color=#305496>" & Range("D6") & "</font>" & "<br>" & Range("G11") & "<font color=#305496>" & Range("A6") & "</font>" & "<br>" & Range("A7") & vbCrLf & vbCrLf & "<font color=#305496>" & Range("C7" _
) & "</font>" & "<br>" & Range("A8") & vbCrLf & vbCrLf & "<font color=#305496>" & Range("C8") & "</font>" & "<br>" & Range("A9") & vbCrLf & vbCrLf & "<font color=#305496>" & Range("B9") & "</font>" & "<br>" & "<br>" & Range("D9") & vbCrLf & vbCrLf & "<font color=#305496>" & Format(Range("E9").Value, "dddd d mmmm yyyy") & "</font>" & "<br>" & "<br>" & Range("A11") & _
vbCrLf & vbCrLf & "<font color=#305496>" & Format(Range("B11").Value, "dddd d mmmm yyyy") & " à " & Range("J18") & "</font>" & "<br>" & Range("C11") & vbCrLf & vbCrLf & "<font color=#305496>" & Format(Range("D11").Value, "dddd d mmmm yyyy") & " vers " & Range("J22") & "</font>" & "<br>" & Range("E11") & vbCrLf & vbCrLf & "<font color=#305496>" & vbCrLf & vbCrLf & [text(E12,"[hh]:mm")] & " -> " & Format(Range("E13").Value, "j hh:mm") & "</font>" & "<br>" & "<br>" & Range("A13") & vbCrLf & vbCrLf & "<font color=#305496>" & Range("B13") & "</font>" & "<br>" & Range("C13") & vbCrLf & vbCrLf & "<font color=#305496>" & Range("D13") & "</font>" & "<br>" & "<br>" & _
Range("A14") & vbCrLf & vbCrLf & "<font color=#305496>" & Range("D14") & "</font>" & "<br>" & "<font color=#305496>" & IIf(Range("A15") = "", "", Range("A15") & "<br>") & IIf(Range("A16") = "", "", Range("A16") & "<br>") & IIf(Range("A17") = "", "", Range("A17") & "<br>") & IIf(Range("A18") = "", "", Range("A18") & "<br>") & IIf(Range("A19") = "", "", Range("A19") & "<br>") & "</font>" & "<br>" & Range("A21") & "<font color=#305496>" & " -> " & Range("C21") & "</font>" & "<br>" & "Type de mission : " & _
"<font color=#305496>" & Range("F21") & "</font>" & "<br>" & "<font color=#305496>" & IIf(Range("A22") = "", "", Range("A22") & "<br>") & IIf(Range("A23") = "", "", Range("A23") & "<br>") & "</font>" & "<font color=#305496>" & IIf(Range("A24") = "", "", Range("A24") & "<br>") & IIf(Range("A25") = "", "", Range("A25") & "<br>") & IIf(Range("A26") = "", "", Range("A26") & "<br>") & IIf(Range("A27") = "", "", Range("A27") & "<br>") & IIf(Range("A28") = "", "", Range("A28") & "<br>") & "</font>" & "<br>" & "</font>" & Range("A30") & vbCrLf & vbCrLf & "<font color=#305496>" & vbCrLf & vbCrLf & Range("B30") & "</font>" & "<br>" & Range("D30") _
& vbCrLf & vbCrLf & "<font color=#305496>" & Range("E30") & "</font>" & "<br>" & Range("D31") & vbCrLf & vbCrLf & "<font color=#305496>" & Range("E31") & "</font>" & "<br>" & "Nombre et nom des passagers : " & "<font color=#305496>" & Range("F32") & "<br>" & IIf(Range("G33") = "", "", Range("G33") & "<br>") & "</font>" & "<br>" & Range("B32") & "<br>" & Range("B33") & vbCrLf & vbCrLf & "<font color=#305496>" & vbCrLf & vbCrLf & Format(Range("C33").Value, "-") & "</font>" & "<br>" & Range("B34") & vbCrLf & vbCrLf & "<font color=#305496>" & Format(Range("C34").Value, "0.000 €") _
& "</font>" & "<br>" & Range("A35") & vbCrLf & vbCrLf & "<font color=#305496>" & Range("G36") & "</font>" & "<br>" & "<br>" & Range("A37") & vbCrLf & vbCrLf & "<font color=#305496>" & Range("B37") & " Km" & "</font>" & "<br>" & "<font color=#305496>" & IIf(Range("D37") = "", "", Range("D37") & "<br>") & "</font>" & "<br>" & Range("A39") & "<br>" & Range("A40") & vbCrLf & vbCrLf & "<font color=#305496>" & Range("A41") & " -> " & vbCrLf & vbCrLf & Format(Range("A43").Value, "00.00 €") & "</font>" & "<br>" & Range("B40") & vbCrLf & vbCrLf & "<font color=#305496>" & Range("B41") & "</font>" & "<br>" & Range( _
"C40") & vbCrLf & vbCrLf & "<font color=#305496>" & Range("C41") & "</font>" & "<br>" & Range("D40") & vbCrLf & vbCrLf & "<font color=#305496>" & Range("D41") & "</font>" & "<br>" & Range("E40") & vbCrLf & vbCrLf & "<font color=#305496>" & Range("E41") & "</font>" & "<br>" & Range( _
"F40") & vbCrLf & vbCrLf & "<font color=#305496>" & Range("F41") & "</font>" & "<br>" & Range("B42") & vbCrLf & vbCrLf & "<font color=#305496>" & Range("B43") & "</font>" & "<br>" & Range("C42") & vbCrLf & vbCrLf & "<font color=#305496>" & Range("C43") & "</font>" & "<br>" & Range("D42") & vbCrLf & vbCrLf & "<font color=#305496>" & Range("D43") & "</font>" & "<br>" & Range("E42") & vbCrLf & vbCrLf & "<font color=#305496>" & Range("E43") & "</font>" & "<br>" & Range("F42") & vbCrLf & vbCrLf & "<font color=#305496>" & Range("F43") & "</font>" & "<br>" & "<br>" & Range("H3") & "<br>" & "<br>" & Range("I3") & vbCrLf & .HTMLBody _
.Attachments.Add xFolder
' If DisplayEmail = False Then
'au lieu de vraiment utiliser "Send", on utilise le "Display" et va simuler le raccoursi "CTRL+Enter" d'Outlook, ce qui est le "SEND"
.Display 'no send
DoEvents
Application.Wait (Now + TimeSerial(0, 0, 5)) 'donner un délai à Outlook pour bien préparer le mail
DoEvents
CreateObject("WScript.Shell").SendKeys ("^{Enter}"), True ' "simuler" un raccourci "CTRL+Enter" (ceci n'est pas 100% sûr)
Application.Wait (Now + TimeSerial(0, 0, 2)) 'donner un délai pour l'envoi
DoEvents
' End If
End With
Else
MsgBox " La feuille de calcul active ne peut pas être vide """
Exit Sub
End If
End Sub