Recherche fichier PDF dans dossier Windows

Résolu
Luca1200 Messages postés 4 Statut Membre -  
 Utilisateur anonyme -
Bonjour à tous,

Un petit nouveau qui à besoin de votre aide précieuse :-)

Je vous expose mon "problème":
Pour le boulot, j'ai du créer un fichier Excel qui regroupe un tas d'informations sur le suivi des dossiers (nom client, date de travaux,...). Dans ce fichier, je dois ajouter deux colonnes qui vont renseigner si nous avons reçu le rapport du client et si celui-ci a été traité.

Les rapports sont stockés dans deux dossiers Windows appelé "RAPPORTS" et "RAPPORTS TRAITES". Dans le dossier "rapports" on retrouve les rapports nommés : "12345678_E", 31546946_G, 45789654_E,... et dans le dossier "rapports traités" on retrouve les rapports traités et donc bon pour l'archivage.

Pour résumer, si le fichier 12345678_E se trouve dans le dossier Windows "RAPPORTS" alors dans la colonne "Rapport reçu" de mon fichier Excel doit apparaître "oui"

1 réponse

  1. Patrice33740 Messages postés 8400 Date d'inscription   Statut Membre Dernière intervention   1 784
     
    Bonjour,

    Utilises la fonction Dir pour analyser les répertoires.
    http://boisgontierjacques.free.fr/pages_site/GestionRepertoire.htm#Dir
    0
    1. Luca1200 Messages postés 4 Statut Membre
       
      Bonjour Patrice,

      Je viens de lire et relire le lien que tu m'as envoyer mais je n'arrive pas à résoudre ce problème.

      Je ne comprends pas comment dire à Excel que si le fichier xxxxxx_E_FT.PDF se touve dans le répertoire X alors "oui" apparaît dans la colonne "U" et sur la ligne correspondant au numéro de dossier.

      J'ai déjà un tas de macro dans ce fichier et je n'y comprends plus rien :-(
      0
    2. Luca1200 Messages postés 4 Statut Membre
       
      Pour être un peu plus clair :

      Private Sub BOUTON_CONTENU_Click()

      'Définition des variables
      Dim i As Integer
      Dim x As Integer
      Dim NomSource As String
      Dim Directory As String
      Dim CC As String
      Dim DTC As String
      Dim EX As Date
      Dim ZONE As String
      Dim SURVEILLANT As String
      Dim FLUIDE As String
      Dim COMMUNE As String
      Dim RUE As String
      Dim ACTETECH As String
      Dim CONTRATAT As String
      Dim GENIECIVILPAR As String
      Dim CONTRATGC As String
      Dim DEMANDEDETRAVAIL1 As String
      Dim DEMANDEDETRAVAIL2 As String
      Dim MULTIPLE As String
      Dim COMMENTAIRE As String
      Dim PROSPECTIONGAZ As String

      'Initilalisation des variables
      x = Workbooks("DOSSIER ENTREP.xlsm").Sheets("VAR").Range("B1")
      i = 2


      Do
      i = i + 1


      NomSource = Worksheets("Feuil2").Cells(i, 1).Value
      Directory = "\\Win.corp.com\dfsroot02\06_0029\30_T_CLIENT\03_T_PLANIFIES\01_COMMUN_3\150. PLATEFORME\ONE DRIVE - PROJET\AVIS\" & NomSource


      Workbooks.Open Directory

      CC = Sheets("Feuil1").Range("B3")
      DTC = Sheets("Feuil1").Range("B4")
      SURVEILLANT = Sheets("Feuil1").Range("B5")
      EX = Sheets("Feuil1").Range("B6")
      FLUIDE = Sheets("Feuil1").Range("B7")
      COMMUNE = Sheets("Feuil1").Range("B9")
      ZONE = Sheets("Feuil1").Range("B10")
      RUE = Sheets("Feuil1").Range("B11")
      NUMERO = Sheets("Feuil1").Range("B12")
      SPW = Sheets("Feuil1").Range("B13")
      ACTETECHNIQUE = Sheets("Feuil1").Range("B15")
      CONTRATAT = Sheets("Feuil1").Range("B16")
      GENIECIVILPAR = Sheets("Feuil1").Range("B17")
      CONTRATGC = Sheets("Feuil1").Range("B18")
      DEMANDEDETRAVAIL1 = Sheets("Feuil1").Range("B20")
      DEMANDEDETRAVAIL2 = Sheets("Feuil1").Range("B21")
      MULTIPLE = Sheets("Feuil1").Range("B22")
      COMMENTAIRE = Sheets("Feuil1").Range("B24")
      PROSPECTIONGAZ = Sheets("Feuil1").Range("B26")

      ActiveWindow.Close


      Workbooks("DOSSIER ENTREP.xlsm").Worksheets("Feuil2").Cells(i, 2).Value = CC
      Workbooks("DOSSIER ENTREP.xlsm").Worksheets("Feuil2").Cells(i, 3).Value = DTC
      Workbooks("DOSSIER ENTREP.xlsm").Worksheets("Feuil2").Cells(i, 4).Value = SURVEILLANT
      Workbooks("DOSSIER ENTREP.xlsm").Worksheets("Feuil2").Cells(i, 5).Value = EX
      Workbooks("DOSSIER ENTREP.xlsm").Worksheets("Feuil2").Cells(i, 6).Value = FLUIDE
      Workbooks("DOSSIER ENTREP.xlsm").Worksheets("Feuil2").Cells(i, 7).Value = COMMUNE
      Workbooks("DOSSIER ENTREP.xlsm").Worksheets("Feuil2").Cells(i, 8).Value = ZONE
      Workbooks("DOSSIER ENTREP.xlsm").Worksheets("Feuil2").Cells(i, 9).Value = RUE
      Workbooks("DOSSIER ENTREP.xlsm").Worksheets("Feuil2").Cells(i, 10).Value = NUMERO
      Workbooks("DOSSIER ENTREP.xlsm").Worksheets("Feuil2").Cells(i, 11).Value = SPW
      Workbooks("DOSSIER ENTREP.xlsm").Worksheets("Feuil2").Cells(i, 12).Value = ACTETECH
      Workbooks("DOSSIER ENTREP.xlsm").Worksheets("Feuil2").Cells(i, 13).Value = CONTRATAT
      Workbooks("DOSSIER ENTREP.xlsm").Worksheets("Feuil2").Cells(i, 14).Value = GENIECIVILPAR
      Workbooks("DOSSIER ENTREP.xlsm").Worksheets("Feuil2").Cells(i, 15).Value = CONTRATGC
      Workbooks("DOSSIER ENTREP.xlsm").Worksheets("Feuil2").Cells(i, 16).Value = DEMANDEDETRAVAIL1
      Workbooks("DOSSIER ENTREP.xlsm").Worksheets("Feuil2").Cells(i, 17).Value = DEMANDEDETRAVAIL2
      Workbooks("DOSSIER ENTREP.xlsm").Worksheets("Feuil2").Cells(i, 18).Value = MULTIPLE
      Workbooks("DOSSIER ENTREP.xlsm").Worksheets("Feuil2").Cells(i, 19).Value = COMMENTAIRE
      Workbooks("DOSSIER ENTREP.xlsm").Worksheets("Feuil2").Cells(i, 20).Value = PROSPECTIONGAZ

      Loop Until i = x + 2
      End Sub
      0
      1. Utilisateur anonyme > Luca1200 Messages postés 4 Statut Membre
         
         
        Bonjour Luca1200,

        Je te propose de remplacer tout le code de ton message #3 par celui-ci :

        
        Option Explicit
        
        
        Private Sub BOUTON_CONTENU_Click()
        
          ' Définition des variables
        
          Dim Directory As String, NomSource As String, PathX As String
          
          Dim CC As String, DTC As String, SURVEILLANT As String, EX As Date, FLUIDE As String
          Dim COMMUNE As String, ZONE As String, RUE As String, NUMERO As Long, SPW As String
          Dim ACTETECH As String, CONTRATAT As String, GENIECIVILPAR As String, CONTRATGC As String
          Dim DEMANDEDETRAVAIL1 As String, DEMANDEDETRAVAIL2 As String, MULTIPLE As String
          Dim COMMENTAIRE As String, PROSPECTIONGAZ As String
          
          Dim dlig As Long, i As Long
        
          ' Initilalisation des variables
        
          Directory = "\\Win.corp.com\dfsroot02\06_0029\30_T_CLIENT\03_T_PLANIFIES\01_COMMUN_3\" _
            & "150. PLATEFORME\ONE DRIVE - PROJET\AVIS\"
        
          dlig = Workbooks("DOSSIER ENTREP.xlsm").Worksheets("VAR").[B1] + 2
        
          For i = 3 To dlig
        
            NomSource = Worksheets("Feuil2").Cells(i, 1): PathX = Directory & NomSource
        
            If Dir(PathX) = "" Then
              MsgBox NomSource & vbLf & " non trouvé dans ..\AVIS", 48, "Fichier introuvable"
            Else
        
              Workbooks.Open PathX
          
              With Worksheets("Feuil1")
                CC = .[B3]: DTC = .[B4]: SURVEILLANT = .[B5]: EX = .[B6]: FLUIDE = .[B7]
                COMMUNE = .[B9]: ZONE = .[B10]: RUE = .[B11]: NUMERO = .[B12]: SPW = .[B13]
                ACTETECH = .[B15]: CONTRATAT = .[B16]: GENIECIVILPAR = .[B17]: CONTRATGC = .[B18]
                DEMANDEDETRAVAIL1 = .[B20]: DEMANDEDETRAVAIL2 = .[B21]: MULTIPLE = .[B22]
                COMMENTAIRE = .[B24]: PROSPECTIONGAZ = .[B26]
              End With
          
              ActiveWindow.Close
        
              With Workbooks("DOSSIER ENTREP.xlsm").Worksheets("Feuil2")
                .Cells(i, 2) = CC
                .Cells(i, 3) = DTC
                .Cells(i, 4) = SURVEILLANT
                .Cells(i, 5) = EX
                .Cells(i, 6) = FLUIDE
                .Cells(i, 7) = COMMUNE
                .Cells(i, 8) = ZONE
                .Cells(i, 9) = RUE
                .Cells(i, 10) = NUMERO
                .Cells(i, 11) = SPW
                .Cells(i, 12) = ACTETECH
                .Cells(i, 13) = CONTRATAT
                .Cells(i, 14) = GENIECIVILPAR
                .Cells(i, 15) = CONTRATGC
                .Cells(i, 16) = DEMANDEDETRAVAIL1
                .Cells(i, 17) = DEMANDEDETRAVAIL2
                .Cells(i, 18) = MULTIPLE
                .Cells(i, 19) = COMMENTAIRE
                .Cells(i, 20) = PROSPECTIONGAZ
                .Cells(i, 21) = "oui"
              End With
            
            End If
        
          Next i
        
        End Sub
        
        

        Dis-moi ce que tu en penses, et si ça marche comme tu veux ; si tu as besoin
        d'un complément d'information, n'hésites pas à me demander.

        Ensuite, si ton problème est réglé, merci d'aller en haut de page pour cliquer
        sur « Marquer comme résolu ».

        Cordialement.  😊
         
        0
      2. Luca1200 Messages postés 4 Statut Membre > Utilisateur anonyme
         
        Bonjour!

        Malheureusement ça ne fonctionne pas. Je me demande s'il va chercher les fichier PDF dans le bon dossier ou s'il reconnait bien les fichier PDF...?

        C'est à la ligne 26 ou 38 qu'il fait cela?

        Merci :-)
        0
      3. Utilisateur anonyme > Luca1200 Messages postés 4 Statut Membre
         
        Bonjour,

        Je ne sais pas exactement ce que tu as en Feuil2, colonne 1 !

        Selon ton code VBA du message #3, je suppose que c'est le nom de tes fichiers
        PDF ; donc si ça ne marche pas, c'est probablement que l'extension n'est pas
        présente, auquel cas il faut la rajouter ainsi :

        
          For i = 3 To dlig
        
              NomSource = Worksheets("Feuil2").Cells(i, 1): PathX = Directory & NomSource & ".pdf"
        
        

        Dis-moi si ça marche comme ça ; j'espère que oui, car sinon,
        il faudra que tu m'envoies ton fichier via Cjoint.

        Cordialement.  😊
         
        0