IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VBA Outlook Discussion :

fichier joint dans un mail automatisé


Sujet :

VBA Outlook

  1. #1
    Membre à l'essai
    Profil pro
    Inscrit en
    Juin 2006
    Messages
    18
    Détails du profil
    Informations personnelles :
    Âge : 46
    Localisation : France

    Informations forums :
    Inscription : Juin 2006
    Messages : 18
    Points : 11
    Points
    11
    Par défaut fichier joint dans un mail automatisé
    bonjour

    j'ai un répertoire avec des fichiers et un feuille excel avec une liste de nom et leur adresse email

    je veux envoyer un fichier précis à une adresse email précis grâce au nom

    pour le premier envoi pas de problème le fichier de A part bien vers A
    mais pour les autres il rajoute les fichiers qu'il a déjà envoyé

    exemple si R est en second il envoyé le fichier de A + fichier de R vers R

    j'arrive pas à voir d’où vient le problème

    merci

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    53
    Sub Nom_fichier()
     
    Dim Fic As String
    Dim nomFichier As String
    Dim RIB As String
    Dim RIB2 As String
    Dim FichierEnvoye As String
     
    On Error Resume Next
     With CreateObject("CDO.Message")
      If Err Then
       MsgBox "CDO non installé"
     Else
     
    Fic = InputBox("Entrez le chemin complet du dossier contenant les fichiers", "Fichiers à envoyer")
     
    nomFichier = Dir(Fic & "\*.xls")
     
    While nomFichier <> ""
     
      For K = 1 To Worksheets("Feuil2").Range("A65536").End(xlUp).Row
       RIB = Worksheets("Feuil2").Cells(K, 1)
       RIB2 = RIB & ".xls"
     
      If RIB2 = nomFichier Then
      FichierEnvoye = Fic & "\" & nomFichier
     
     .From = "AA@AAAA.FR"
     .To = Worksheets("Feuil2").Cells(i, 2)
     .Subject = Worksheets("Feuil2").Cells(i, 1)
     .HTMLBody = "Test"
     .AddAttachment (FichierEnvoye)
     .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = X
     .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "XXXX"
     .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = XX
     .Configuration.Fields.Update
    On Error Resume Next
     .Send
     
      End If
      Next K
     
    nomFichier = Dir
    i = i + 1
    Wend
     
     End If
     
    On Error GoTo 0
     
    End With
     
    End Sub

  2. #2
    Modérateur
    Avatar de l_autodidacte
    Homme Profil pro
    Retraité : Directeur de lycée/Professeur de sciences physiques
    Inscrit en
    Juillet 2009
    Messages
    2 416
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 69
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Retraité : Directeur de lycée/Professeur de sciences physiques
    Secteur : Enseignement

    Informations forums :
    Inscription : Juillet 2009
    Messages : 2 416
    Points : 5 808
    Points
    5 808
    Par défaut
    D'après le code tu es entrain d'utiliser soit VB6 soit VBA(à cause du typage des variables en plus La fonction Dir n'est pas disponible en VBScript).

  3. #3
    Membre à l'essai
    Profil pro
    Inscrit en
    Juin 2006
    Messages
    18
    Détails du profil
    Informations personnelles :
    Âge : 46
    Localisation : France

    Informations forums :
    Inscription : Juin 2006
    Messages : 18
    Points : 11
    Points
    11
    Par défaut
    oui c'est du vba , comment je peux déplacer ma discussion dans le bon forum?

  4. #4
    Expert éminent
    Avatar de Oliv-
    Homme Profil pro
    solution provider
    Inscrit en
    Mars 2006
    Messages
    4 087
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : solution provider

    Informations forums :
    Inscription : Mars 2006
    Messages : 4 087
    Points : 7 168
    Points
    7 168
    Billets dans le blog
    20
    Par défaut
    Bonjour,

    On peut faire autrement:

    Si j'ai bien compris tu as un fichier excel et tu parcours les lignes pour envoyer le fichier RIB correpondant à un destinataire ?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    Sub Nom_fichier()
     
    Dim Fic As String
    Dim nomFichier As String
    Dim RIB As String
    Dim RIB2 As String
    Dim FichierEnvoye As String
     
    On Error Resume Next
     With CreateObject("CDO.Message")
      If Err Then
       MsgBox "CDO non installé"
     Else
     
    Fic = InputBox("Entrez le chemin complet du dossier contenant les fichiers", "Fichiers à envoyer")
     
      For K = 1 To Worksheets("Feuil2").Range("A65536").End(xlUp).Row
       RIB = Worksheets("Feuil2").Cells(K, 1)
       RIB2 = RIB & ".xls"
     
     FichierEnvoye = Fic & "\" & RIB2 
      If len(dir(FichierEnvoye) >0 Then
     
     .From = "AA@AAAA.FR"
     .To = Worksheets("Feuil2").Cells(i, 2)
     .Subject = Worksheets("Feuil2").Cells(i, 1)
     .HTMLBody = "Test"
     .AddAttachment (FichierEnvoye)
     .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = X
     .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "XXXX"
     .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = XX
     .Configuration.Fields.Update
    On Error Resume Next
     .Send
     
      End If
      Next K
     
    i = i + 1
     
     End If
     
    On Error GoTo 0
     
    End With
     
    End Sub

  5. #5
    Membre à l'essai
    Profil pro
    Inscrit en
    Juin 2006
    Messages
    18
    Détails du profil
    Informations personnelles :
    Âge : 46
    Localisation : France

    Informations forums :
    Inscription : Juin 2006
    Messages : 18
    Points : 11
    Points
    11
    Par défaut
    marche pas

    Alors j'ai un classeur exel regroupant dans la colonne A les rib et la colonne B les email des destinataires
    dans un dossier j'ai X fichiers où leur nom correspond est le rib

    le but c'est d'envoyer le fichier BSD à BSD@XX , fichier ERD à ERD@XX, ect

    actuellement avec le code cela me fait BSD est envoyé à BSD , ERD reçoit les fichiers ERD+BSD, ect ect le suivant a qui on lui envoi l'email reçoit tous les fichiers précedents déjà envoyer à d'autres alors que je ne veux qu'il ne reçoivent que son fichier à lui.


    le probleme viendrait de attachments son count augmente a chaque envoie comment el remettre à zero ?

  6. #6
    Expert éminent
    Avatar de Oliv-
    Homme Profil pro
    solution provider
    Inscrit en
    Mars 2006
    Messages
    4 087
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : solution provider

    Informations forums :
    Inscription : Mars 2006
    Messages : 4 087
    Points : 7 168
    Points
    7 168
    Billets dans le blog
    20
    Par défaut
    et avec ça :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    53
    54
    55
    Sub Nom_fichier()
     
        Dim Fic As String
        Dim nomFichier As String
        Dim RIB As String
        Dim RIB2 As String
        Dim FichierEnvoye As String
        Dim Cdo_Message As Object
     
     
     
     
        Fic = InputBox("Entrez le chemin complet du dossier contenant les fichiers", "Fichiers à envoyer")
     
        For k = 1 To Worksheets("Feuil2").Range("A65536").End(xlUp).Row
            RIB = Worksheets("Feuil2").Cells(k, 1).Value
            RIB2 = RIB & ".xls"
     
            If Not Right(Fic, 1) = "\" Then Fic = Fic & "\"
            FichierEnvoye = Fic & RIB2
            If Len(Dir(FichierEnvoye)) > 0 Then
                On Error Resume Next
                Set Cdo_Message = CreateObject("CDO.Message")
                On Error Resume Next
                If Err Then
                    MsgBox "CDO non installé"
                    Exit Sub
                Else
                    With Cdo_Message
                        .From = "octu@grassavoye.com"
                        .To = Worksheets("Feuil2").Cells(k, 2)
                        .Subject = Worksheets("Feuil2").Cells(k, 1)
                        .HTMLBody = "Test"
                        .AddAttachment (FichierEnvoye)
                        .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
                        .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.xxxx.com"
                        .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
                        .Configuration.Fields.Update
                        On Error Resume Next
                        .Send
                        If Err <> 0 Then
                            MsgBox Err.Number & Err.Description & Err.LastDllError
     
                            Err.Clear
                        End If
                    End With
                End If
     
            End If
        Next k
     
        On Error GoTo 0
     
     
    End Sub

  7. #7
    Membre à l'essai
    Profil pro
    Inscrit en
    Juin 2006
    Messages
    18
    Détails du profil
    Informations personnelles :
    Âge : 46
    Localisation : France

    Informations forums :
    Inscription : Juin 2006
    Messages : 18
    Points : 11
    Points
    11
    Par défaut
    je crois que c'est bon je vais faire qqtest et je reviendrai informé si c'est résolu

    merci beaucoup

Discussions similaires

  1. [XL-2010] Macro - renommer un fichier envoyé en pièce jointe dans un mail !
    Par nico2no dans le forum Macros et VBA Excel
    Réponses: 5
    Dernier message: 21/11/2014, 16h32
  2. [Joomla!] récupération fichier joint dans un mail à partir d'un formulaire
    Par mgmgmg dans le forum EDI, CMS, Outils, Scripts et API
    Réponses: 2
    Dernier message: 16/07/2010, 08h57
  3. extraire fichier joint dans un mail
    Par ramsesthebest dans le forum Web
    Réponses: 5
    Dernier message: 20/12/2007, 14h52
  4. [Mail] fichier attache dans un mail
    Par yiannis dans le forum Langage
    Réponses: 5
    Dernier message: 06/10/2005, 14h31
  5. Limiter taille fichier joint à un mail
    Par fdthierry dans le forum Applications et environnements graphiques
    Réponses: 2
    Dernier message: 27/08/2004, 12h12

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo