Excel en PDF via outlook

momo2394

XLDnaute Occasionnel
Bonjour

J'ai une macro qui transforme Excel en PDF et l'envoi automatiquement via Outlook qui fonctionne très bien, juste un petit hic c'est que le fichier Excel change de nom tous les jours mais la macro ne tiens compte que du fichier "Compte rendu Minerve du 03 novembre 2011.
Comment peut on faire pour que le pdf se crée en fonction du nom du fichier Excel

.attachments.Add (("C:\Documents and Settings\Momo2394\Bureau\Compte Rendu Minerve du 03 novembre 2011.pdf"))
***************************************************************************

Sub ToPdf()
Set pdfjob = CreateObject("PDFCreator.clsPDFCreator")
NomExcel = ThisWorkbook.Name
NomPdf = Left(NomExcel, Len(NomExcel) - 4) & ".pdf"
With pdfjob
If .cstart("/NoProcessingAtStartup") = False Then
MsgBox "Can't initialize PDFCreator.", vbCritical + vbOKOnly, "PrtPDFCreator"
Exit Sub
End If
.cOption("UseAutosave") = 1
.cOption("UseAutisaveDirectory") = 1
.cOption("AutosaveDirectory") = ThisWorkbook.Path
.cOption("AutosaveFilename") = NomPdf
.cOption("AutosaveFormat") = 0
.cClearCache
End With
ThisWorkbook.PrintOut copies:=1, ActivePrinter:="PDFCreator"
Do Until pdfjob.cCountOfPrintjobs = 1
DoEvents
Loop
pdfjob.cPrinterStop = False
Do Until pdfjob.cCountOfPrintjobs = 0
DoEvents
Loop
With pdfjob
.cDefaultprinter = DefaultPrinter
.cClearCache
.cClose
End With
Set pdfjob = Nothing

Dim OutApp As Object
Dim OutMail As Object
Dim corps As String
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(olMailItem)
corps = "<font style='font-family: Tahoma ;font-size: 12pt ;' color=midnightblue>Madame, Monsieur,<br><br>Veuillez trouvez ci-joint les details du jour<BR><BR><BR><BR><BR><BR><BR>Meilleurs Salutations<BR>adresse1<BR>--------------------------------------------------------------------------------<BR>adresse2<BR><BR>--------------------------------------------------------------------------------</font>"
With OutMail
.To = "email1@test.fr;email2@test.fr"
.CC = "email3@test3;email4@test.fr"
.bcc = ""
.Subject = "Compte Rendu Minerve "
.HTMLBody = corps
.attachments.Add (("C:\Documents and Settings\Momo2394\Bureau\Compte Rendu Minerve du 03 novembre 2011.pdf"))
.Save
.display ' affiche le mail
'.send 'pour l'envoyer de façon auto
End With
End Sub


Merci
 

Discussions similaires

Statistiques des forums

Discussions
312 464
Messages
2 088 630
Membres
103 894
dernier inscrit
tanyroc