Précédent   Forum des professionnels en informatique > Logiciels > Microsoft Office > Excel > Macros et VBA Excel
Macros et VBA Excel Vos questions relatives aux macros Excel, à l'utilisation de VBA et à l'automatisation de vos classeurs Excel.
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 08/11/2011, 09h14   #1
Débutant
 
Avatar de FCL31
 
Inscription : août 2007
Messages : 672
Détails du profil
Informations personnelles :
Âge : 31

Informations forums :
Inscription : août 2007
Messages : 672
Points : 184
Points : 184
Envoyer un message via MSN à FCL31
Par défaut Probléme d'envoie par mail de fichier Excel en pdf

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
Fichiers attachés
Type de fichier : xls Test DDE Repos.xls (39,5 Ko, 2 affichages)
FCL31 est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 14h17.


 
 
 
 
Partenaires

Hébergement Web