Recherche de mot

Résolu
bonjour,
Je suis actuellement responsable d'un contrat. Pour la gestion des défauts, mon client m'envoi un mail avec en pièce jointe un fichier Word qui contient les informations nécessaires à la réalisation du travail.
J'utilise un fichier excel pour le suivie de mes activités et la facturation.

Je souhaiterais que mon fichier excel recherche les information dont j'ai besoin dans le fichier Word et se complète automatiquement (tel que : nom du client, type de travail, description du travail, bâtiment, numéro de défauts, ...)

Le fichier Word qui m'est envoyé est toujours de forme identique avec ces même mots clefs.

Mon projet est t'il réalisable ?

Merci

6 réponses

  • Votes
  • Date
  • Date décroissante
  1. le fichier Word que je reçois est de ce type :



    et le fichier Excel serait comme cela :

    1. Bonjour,

      une image ne fournit pas les indications de structure du document word (signets, tableaux).
      envoie plutôt le fichier.

      cdlt
    2. @JvDoOn ne peut pas déposer de fichier sur CCM ?
    3. tu peux passer par cjoint.com et tu colles dans ton prochain message le lien qu'ils t'auront calculé.

      cdlt
  2. Je viens de découvrir ton fichier, et il est sous forme de tableau, donc tu peux faire comme sous Excel, c'est-à-dire que la première case (ligne 1, colonne 1 = A1).

    Le code doit jongler entre Excel et Word.
    1. Bonjour,

      Voici un code avec 2 solutions :
      la première est un copier coller du tableau de word vers excel
      la seconde est une recopie cellule par cellule.
      Sub récup_word_fault_2()
      
          Dim wdapp As Word.Application
          Dim wdoc As Word.Document
          Dim objtable As Word.Table
          Dim nomfich As String
          
          nomfich = "E:\Users\jvdo\forum\ccm_Fault.doc"
           
          Set wdapp = CreateObject("Word.Application") 'creation session Word
          wdapp.Visible = True
          On Error Resume Next
      
          wdapp.Documents.Open Filename:=nomfich
          Set wdoc = wdapp.activeDocument
          Set objtable = wdoc.tables(1)
      
      '1ère méthode : copier/coller du tableau
          objtable.Range.Copy
          ActiveSheet.Range("B20").Select
          ActiveSheet.Paste
      
      '2ème méthode : remplissage cellule par cellule
          With ActiveSheet
              .Cells(2, 2) = WorksheetFunction.Substitute(objtable.Cell(1, 1).Range.Text, Chr(7), "")
              .Cells(2, 3) = WorksheetFunction.Substitute(objtable.Cell(1, 2).Range.Text, Chr(7), "")
              .Cells(3, 2) = WorksheetFunction.Substitute(objtable.Cell(1, 4).Range.Text, Chr(7), "")
              .Cells(3, 3) = WorksheetFunction.Substitute(objtable.Cell(1, 5).Range.Text, Chr(7), "")
              .Cells(4, 2) = WorksheetFunction.Substitute(objtable.Cell(1, 6).Range.Text, Chr(7), "")
              .Cells(4, 3) = WorksheetFunction.Substitute(objtable.Cell(1, 7).Range.Text, Chr(7), "")
              .Cells(5, 2) = WorksheetFunction.Substitute(objtable.Cell(3, 1).Range.Text, Chr(7), "")
              .Cells(5, 3) = WorksheetFunction.Substitute(objtable.Cell(3, 2).Range.Text, Chr(7), "")
              .Cells(6, 2) = WorksheetFunction.Substitute(objtable.Cell(5, 1).Range.Text, Chr(7), "")
              .Cells(6, 3) = WorksheetFunction.Substitute(objtable.Cell(5, 2).Range.Text, Chr(7), "")
              .Cells(7, 2) = WorksheetFunction.Substitute(objtable.Cell(5, 4).Range.Text, Chr(7), "")
              .Cells(7, 3) = WorksheetFunction.Substitute(objtable.Cell(5, 5).Range.Text, Chr(7), "")
              .Cells(8, 2) = WorksheetFunction.Substitute(objtable.Cell(7, 1).Range.Text, Chr(7), "")
              .Cells(8, 3) = WorksheetFunction.Substitute(objtable.Cell(7, 2).Range.Text, Chr(7), "")
              .Cells(9, 2) = WorksheetFunction.Substitute(objtable.Cell(7, 4).Range.Text, Chr(7), "")
              .Cells(9, 3) = WorksheetFunction.Substitute(objtable.Cell(7, 5).Range.Text, Chr(7), "")
              .Cells(10, 2) = WorksheetFunction.Substitute(objtable.Cell(9, 1).Range.Text, Chr(7), "")
              .Cells(10, 3) = WorksheetFunction.Substitute(objtable.Cell(9, 2).Range.Text, Chr(7), "")
              .Cells(11, 2) = WorksheetFunction.Substitute(objtable.Cell(9, 4).Range.Text, Chr(7), "")
              .Cells(11, 3) = WorksheetFunction.Substitute(objtable.Cell(9, 6).Range.Text, Chr(7), "")
              .Cells(12, 2) = WorksheetFunction.Substitute(objtable.Cell(11, 1).Range.Text, Chr(7), "")
              .Cells(12, 3) = WorksheetFunction.Substitute(objtable.Cell(11, 2).Range.Text, Chr(7), "")
              .Cells(13, 2) = WorksheetFunction.Substitute(objtable.Cell(11, 4).Range.Text, Chr(7), "")
              .Cells(13, 3) = WorksheetFunction.Substitute(objtable.Cell(11, 5).Range.Text, Chr(7), "")
              .Cells(14, 2) = WorksheetFunction.Substitute(objtable.Cell(13, 1).Range.Text, Chr(7), "")
              .Cells(14, 3) = WorksheetFunction.Substitute(objtable.Cell(14, 1).Range.Text, Chr(7), "")
              .Cells(15, 2) = WorksheetFunction.Substitute(objtable.Cell(16, 1).Range.Text, Chr(7), "")
              .Cells(15, 3) = WorksheetFunction.Substitute(objtable.Cell(16, 2).Range.Text, Chr(7), "")
              .Cells(16, 2) = WorksheetFunction.Substitute(objtable.Cell(17, 1).Range.Text, Chr(7), "")
              .Cells(16, 3) = WorksheetFunction.Substitute(objtable.Cell(17, 2).Range.Text, Chr(7), "")
              
          End With
          wddoc.Close False
          wdapp.Quit
      
      End Sub


      J'ai laissé word visible pour le débogage et tu dois modifier le chemin de ton fichier.

      cordialement
      1. merci c'est exactement ce que je voulais faire !
        Mais, car il y a un mais... le nom du fichier que je reçois n'est jamais le même et en temps normal je ne l'enregistre pas, il est dans ma boite mail, je l'ouvre et le recopie manuellement
    2. Bonjour, quand tu ouvre un fichier se trouvant dans ta boîte mail, il s'enregistre, en arrière-plan, dans le dossier temp se trouvant généralement dans C:\Users\ton nom\Local\Temp (le chemin varie suivant la version de Windows).

      Il te suffiras de changer le chemin du fichier dans le code proposé par JvDo
      1. Merci beaucoup pour vos réponse, j'ai réussi à obtenir le résultat souhaité. Le fichier et fini mais j'ai encore deux petit soucie à régler... j'ai créé une nouvelle discutions pour ne pas polluer celle ci (https://forums.commentcamarche.net/forum/affich-32376857-diminution-de-codes si vous pouviez encore m'aider je vous en serais reconnaissant.
        il faut s'armer de courage si vous vous lancez dans mes questions suivantes...