Bonjours a tous
Voila j'ai un problème avec mon code
Code :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
| Private Sub Sauver_Click()
Dim a As Worksheet
Dim sc As Workbook
Dim nouveauNom As String
Dim OlApp As Outlook.Application
Dim OlItem As Outlook.MailItem
Set a = ActiveSheet
Set OlApp = New Outlook.Application
Set OlItem = OlApp.CreateItem(olMailItem)
Application.ScreenUpdating = False
nouveauNom = "DDE du " & Range("B40").Text & " " & Range("D40").Text & Range("E40").Text
nouveauNom = Replace(nouveauNom, "/", "_")
Set sc = Workbooks.Add(xlWBATWorksheet)
sc.SaveAs (nouveauNom & ".xls")
a.Copy Before:=sc.Sheets(1)
ActiveSheet.PrintOut copies:=1, ActivePrinter:="PDFCreator"
With OlItem
.To = "machin@truc.com"
.Subject = nouveauNom
.Body = nouveauNom
.Attachments.Add ("C:\Documents and Settings\fp\Bureau\PDF\" & nouveauNom & ".pdf")
.Categories = "Daily"
.OriginatorDeliveryReportRequested = True
.ReadReceiptRequested = True
.Display 'Send '<<<<<<<<<<<<<<<TO SEND DIRECTLY
End With
Set OlItem = Nothing
Set OlApp = Nothing
Workbooks(nouveauNom & ".xls").Close SaveChanges:=False
Kill nouveauNom & ".xls"
'----------------------------------------------------------------------------
FileCopy ("C:\Documents and Settings\fp\Bureau\PDF\" & nouveauNom & ".pdf"), ("\\HP\Company\DataUser\UserFP\Re\" & nouveauNom & ".pdf")
Kill ("C:\Documents and Settings\fp\Bureau\PDF\" & nouveauNom & ".pdf")
'--------------------------------------------------------------------
Application.ScreenUpdating = True
Application.DisplayAlerts = False
Application.Quit
End Sub |
En gros j'imprime mon fichier Excel en pdf en le dossier : "C:\Documents and Settings\fp\Bureau\PDF\"
Jusque là pas de problème
Ensuite, j'envoie ce fichier pdf par mail en pièce jointe
Là problème : il me dit que le fichier est introuvable
Je regarde donc dans le dossier "C:\Documents and Settings\fp\Bureau\PDF\" et le fichier est bien là.
Je comprend pas
PS : lorsqu'il y a l'erreur, et que j’arrête la procédure (Débogage), et que je relance la macro, sa marche.
Je suis perdu