Tout ets dans la même procédure.
Après le saveAs J'utilise dans mon mail .Attachments.Add ActiveWorkbook.FullName donc le ActiveWorkbook devrais être celui que je viens d'enregistrer sous puisqu'il n'y en a que 1 d'ouvert ?
La actuellement dans mon mail est joint la version "vierge" du fichier et non celle que j'ai juste avant sauvegardé
Sub Mail()
Dim i As Integer, s As String
Dim OutApp As Object
Dim OutMail As Object
Dim rng As Object
Dim wdDoc As Object
Dim sPath As String
Dim SigString As String, Signature As String
Dim Texte As String
Dim t As String
t = Range("B36")
Dim ColisDispo As String
If Range("L67") + Range("L69") + Range("L71") + Range("L73") + Range("L75") + Range("L77") > 1 Then
ColisDispo = "Les colis sont préparés et mis à disposition dans la zone d'envoi."
Else
ColisDispo = "Le colis est préparé et mis à disposition dans la zone d'envoi."
End If
Dim W1 As Workbook
Dim chemin As String
chemin = "C:\Users\blablabla\Desktop\"
Set W1 = ThisWorkbook
Application.DisplayAlerts = False
DoEvents
ActiveSheet.Shapes("Picture 4").Visible = False
With Application.FileDialog(msoFileDialogSaveAs) 'Dialogs(xlDialogSaveAs)
.InitialFileName = CStr(Range("V19")) & " Demande de transport.xlsm"
.FilterIndex = 2
.Show
End With
On Error Resume Next
'Prepare le mail
Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)
Set wdDoc = OutMail.Getinspector.wordeditor
' Récupérer le nom du fichier de signature
sPath = "C:\Users\gpetit\AppData\Roaming\Microsoft\Signatures\"
SigString = Dir(sPath & "*.htm")
If SigString <> "" Then
Signature = GetBoiler(sPath & SigString)
Else
Signature = ""
End If
With OutMail
.to = "Logistique.GROUPE@plastivaloire.com"
.Subject = Range("D8") & " Demande d'expédition du CEss => " & Range("D42")
Texte = "Bonjour," & "<br><br>" & "Trouvez ci-joint une demande d'expédition vers " & Range("D42") & " " & Range("D47") & " correspondante à la Commande DT Eotp " & Right(t, Len(t) - InStrRev(t, " ")) & "." & "<br><br>" & ColisDispo
.htmlbody = Texte & "<br><br>" & Signature
MsgBox ActiveWorkbook.FullName
.Attachments.Add ActiveWorkbook.FullName
.Display
End With
On Error GoTo 0
OutApp.Session.Logoff
Set OutMail = Nothing
Set OutApp = Nothing
Application.DisplayAlerts = True
ActiveSheet.Shapes("Picture 4").Visible = True
ActiveWorkbook.Save
End Sub
Donc en gros version simplifié du code (j'enleve ce qui sert a rien) :
Sub Mail()
chemin = "C:\Users\blablabla\Desktop\"
Set W1 = ThisWorkbook
With Application.FileDialog(msoFileDialogSaveAs) 'Dialogs(xlDialogSaveAs)
.InitialFileName = CStr(Range("V19")) & " Demande de transport.xlsm"
.FilterIndex = 2
.Show
End With
On Error Resume Next
'Prepare le mail
Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)
Set wdDoc = OutMail.Getinspector.wordeditor
With OutMail
.to = "Logistique.GROUPE@plastivaloire.com"
.Subject = Range("D8") & " Demande d'expédition du CEss => " & Range("D42")
Texte = "Bonjour," & "<br><br>" & "Trouvez ci-joint une demande d'expédition vers " & Range("D42") & " " & Range("D47") & " correspondante à la Commande DT Eotp " & Right(t, Len(t) - InStrRev(t, " ")) & "." & "<br><br>" & ColisDispo
.htmlbody = Texte & "<br><br>" & Signature
MsgBox ActiveWorkbook.FullName
.Attachments.Add ActiveWorkbook.FullName
.Display
End With
On Error GoTo 0
OutApp.Session.Logoff
Set OutMail = Nothing
Set OutApp = Nothing
Application.DisplayAlerts = True
ActiveWorkbook.Save
End Sub