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
|
Sub RepererLesIndex()
Dim I As Long, J As Long, IndexMatrice As Long
Dim Contenu As String, ContenuNom As String, ContenuPrenoms As String, ListeDesPrenoms As Variant, PageDocument As String
Dim MatriceNomsPrenoms() As Variant
With ActiveDocument
IndexMatrice = 0
For I = 1 To .Indexes(2).Range.Paragraphs.Count
Contenu = .Indexes(2).Range.Paragraphs(I).Range.Text
If UBound(Split(Contenu, ":")) > 0 Then
ContenuNom = Split(Contenu, ":")(0)
ContenuPrenoms = Trim(Split(Contenu, ":")(1))
If UBound(Split(ContenuPrenoms, ";")) = 0 Then
ReDim Preserve MatriceNomsPrenoms(2, IndexMatrice)
MatriceNomsPrenoms(0, IndexMatrice) = Trim(ContenuNom)
MatriceNomsPrenoms(1, IndexMatrice) = Trim(Split(ContenuPrenoms, ",")(0))
PageDocument = Split(ContenuPrenoms, ",")(1)
MatriceNomsPrenoms(2, IndexMatrice) = Mid(PageDocument, 1, Len(PageDocument) - 1)
IndexMatrice = IndexMatrice + 1
Else
ListeDesPrenoms = Split(ContenuPrenoms, ";")
For J = LBound(ListeDesPrenoms) To UBound(ListeDesPrenoms)
ReDim Preserve MatriceNomsPrenoms(2, IndexMatrice)
MatriceNomsPrenoms(0, IndexMatrice) = Trim(ContenuNom)
MatriceNomsPrenoms(1, IndexMatrice) = Split(ListeDesPrenoms(J), ",")(0)
PageDocument = Split(ListeDesPrenoms(J), ",")(1)
MatriceNomsPrenoms(2, IndexMatrice) = PageDocument
IndexMatrice = IndexMatrice + 1
Next J
MatriceNomsPrenoms(2, IndexMatrice - 1) = Mid(PageDocument, 1, Len(PageDocument) - 2)
End If
End If
Next I
' Restitution de la matrice
For IndexMatrice = LBound(MatriceNomsPrenoms, 2) To UBound(MatriceNomsPrenoms, 2)
Debug.Print IndexMatrice & " - " & MatriceNomsPrenoms(0, IndexMatrice) & " - " & MatriceNomsPrenoms(1, IndexMatrice) & " - " & MatriceNomsPrenoms(2, IndexMatrice)
Next IndexMatrice
End With
End Sub |