View Single Post
 
Old 12-04-2020, 07:40 AM
jpl jpl is offline Windows 7 64bit Office 2010 32bit
Advanced Beginner
 
Join Date: Jan 2016
Location: France
Posts: 33
jpl is on a distinguished road
Default

Cela ne me dérange pas, ça m'occupe en ces temps de confinement.
Voici une nouvelle version complétée : la sortie se fait dans un fichier texte qui s'enregistre dans la racine du disque C.
Bien entendu, la terrifiante malédiction a été exorcisée, du moins je l'espère.

Pour une sortie sur Excel, c'est bien sûr faisable, mais je n'en sais pas assez.

Code:
Sub Essai()
  Dim Trouvé As String, ListeTrouvés As String
  Dim Prefixes As Variant, Prefixe As Variant
  Dim Total As Long
  
  'pour sortie dans un fichier texte
  Dim SortieFichier As Integer
  
  ListeTrouvés = " "
  Prefixes = Array("PE-", "JEB-", "HEL-")
  
  For Each Prefixe In Prefixes

    With ActiveDocument.Content.Find
      .ClearFormatting
      .MatchWildcards = True
      .Text = Prefixe & "[0-9]{1,}"
      .Forward = True
      .Execute

      Do While .Found
        Trouvé = .Parent.Text
        If InStr(1, ListeTrouvés, Trouvé & " ") = 0 Then
          ListeTrouvés = ListeTrouvés & Trouvé & " "
          Total = Total + 1
        End If
        .Execute
      Loop

    End With
  Next Prefixe
  
  ListeTrouvés = Trim(ListeTrouvés)
  ListeTrouvés = Replace(ListeTrouvés, " ", vbCrLf)
  ListeTrouvés = ListeTrouvés & vbCrLf & "Total = " & CStr(Total)
  
  'Sortie des résultats dans le fichier texte
  SortieFichier = FreeFile
  Open "c:\SortieFichier.txt" For Output As #SortieFichier
  Print #SortieFichier, ListeTrouvés
  Close #SortieFichier
End Sub

Last edited by jpl; 12-04-2020 at 08:02 AM. Reason: Corrections mineures
Reply With Quote