Renommer pièce jointe PDF macro excel et Outlook
Résolu
orould
Messages postés
390
Date d'inscription
Statut
Membre
Dernière intervention
-
orould Messages postés 390 Date d'inscription Statut Membre Dernière intervention -
orould Messages postés 390 Date d'inscription Statut Membre Dernière intervention -
Bonjour,
Je cherche à générer automatiquement un bon de commande qui ait en pièce jointe ma feuille PDF. Le problème est que j'arrive à enregistrer avec le nom que je souhaite en PDF, j'arrive à créer le mail, je n'arrive pas à renommer la pièce jointe, elle garde le nom "Mafeuille.PDF". Si vous pouvez m'aider, merci
Sub SendWithAtt()
Dim Rep As Integer
i = [B7].Value
Rep = MsgBox("Voulez-vous envoyer le bon de commande chez " & i, vbYesNo + vbQuestion, "mDF XLpages.com")
If Rep = vbYes Then
' ici le traitement si réponse positive
' ...
Dim fichier As String
fichier = "D:\Moi\Desktop\zik\" & [E5].Value & "_" & [B3].Value
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=fichier, _
Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=False
Dim olApp As Outlook.Application
Dim olMail As MailItem
Dim CurFile As String
Set olApp = New Outlook.Application
Set olMail = olApp.CreateItem(olMailItem)
CurFile = ThisWorkbook.Path & "\" & "MaFeuille.Pdf"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=CurFile, _
Quality:=xlQualityStandard, IncludeDocProperties:=False, IgnorePrintAreas:=False, _
OpenAfterPublish:=False
With olMail
.To = [L9].Value
.Subject = [E5].Value & "_" & [B3].Value
.Body = "Vous trouverez ci-joint le fichier PDF ..."
.Attachments.Add CurFile
.Display '.Send
End With
Else
' ici le traitement si réponse négative
' ...
End If
' Effacer les variables objets
Set olMail = Nothing
Set olApp = Nothing
End Sub
Je cherche à générer automatiquement un bon de commande qui ait en pièce jointe ma feuille PDF. Le problème est que j'arrive à enregistrer avec le nom que je souhaite en PDF, j'arrive à créer le mail, je n'arrive pas à renommer la pièce jointe, elle garde le nom "Mafeuille.PDF". Si vous pouvez m'aider, merci
Sub SendWithAtt()
Dim Rep As Integer
i = [B7].Value
Rep = MsgBox("Voulez-vous envoyer le bon de commande chez " & i, vbYesNo + vbQuestion, "mDF XLpages.com")
If Rep = vbYes Then
' ici le traitement si réponse positive
' ...
Dim fichier As String
fichier = "D:\Moi\Desktop\zik\" & [E5].Value & "_" & [B3].Value
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=fichier, _
Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=False
Dim olApp As Outlook.Application
Dim olMail As MailItem
Dim CurFile As String
Set olApp = New Outlook.Application
Set olMail = olApp.CreateItem(olMailItem)
CurFile = ThisWorkbook.Path & "\" & "MaFeuille.Pdf"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=CurFile, _
Quality:=xlQualityStandard, IncludeDocProperties:=False, IgnorePrintAreas:=False, _
OpenAfterPublish:=False
With olMail
.To = [L9].Value
.Subject = [E5].Value & "_" & [B3].Value
.Body = "Vous trouverez ci-joint le fichier PDF ..."
.Attachments.Add CurFile
.Display '.Send
End With
Else
' ici le traitement si réponse négative
' ...
End If
' Effacer les variables objets
Set olMail = Nothing
Set olApp = Nothing
End Sub
2 réponses
-
Bonjour,
Changer cela:
CurFile = ThisWorkbook.Path & "\" & "MaFeuille.Pdf"
par ceci:
Name ThisWorkbook.Path & "\" & "MaFeuille.Pdf" As ThisWorkbook.Path & "\" & "Nouveaunom.Pdf" CurFile = ThisWorkbook.Path & "\" & "Nouveaunom.Pdf"
-
Merci pour la réponse, j'y suis presque. Le nom change mais il faut qu'il soit variable (E5_B3) j'ai essayé :
Name ThisWorkbook.Path & "\" & "MaFeuille.Pdf" As ThisWorkbook.Path & "\" & [E5].Value & "_" & [B3].Value CurFile = ThisWorkbook.Path & "\" & [E5].Value & "_" & [B3].Value
Mais ça ne fonctionne pas, si je peux avoir encore un petit coup de main, merci !-
-
-
-
Il manque là aussi l'extension
Dim fichier As String fichier = "D:\Moi\Desktop\zik\" & [E5].Value & "_" & [B3].Value ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=fichier, _ Quality:=xlQualityStandard, IncludeDocProperties:=True, _ IgnorePrintAreas:=False, OpenAfterPublish:=False
Je ne comprends pas si tu enregistres sous un nom, pourquoi le renommer. Enregistre le directement sous le bon nom! -
Parce que je n'y arrivais pas, mais grâce (je garde l'accent) à toi c'est bon :) Merci !
voilà mon code final si ça peut aider d'autre gens :
Sub SendWithAtt() Dim Rep As Integer i = [B7].Value Rep = MsgBox("Voulez-vous envoyer le bon de commande chez " & i, vbYesNo + vbQuestion, "mDF XLpages.com") If Rep = vbYes Then ' ici le traitement si réponse positive ' ... Dim fichier As String fichier = "D:\moi\Desktop\zik\" & [E5].Value & "_" & [B3].Value ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=fichier, _ Quality:=xlQualityStandard, IncludeDocProperties:=True, _ IgnorePrintAreas:=False, OpenAfterPublish:=False Dim olApp As Outlook.Application Dim olMail As MailItem Dim CurFile As String Set olApp = New Outlook.Application Set olMail = olApp.CreateItem(olMailItem) With olMail .To = [L9].Value .Subject = [E5].Value & "_" & [B3].Value .Body = "Vous trouverez ci-joint le fichier PDF ..." .Attachments.Add ThisWorkbook.Path & "\" & [E5].Value & "_" & [B3].Value & ".Pdf" .Display '.Send End With Else ' ici le traitement si réponse négative ' ... End If ' Effacer les variables objets Set olMail = Nothing Set olApp = Nothing End Sub
-