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
|
Option Explicit
Sub RepererLesLignes()
Dim DocEnCours As Document
Dim I As Long, IndexListe As Long
Dim ChaineATrouver As Variant
Dim ListeDesParagraphes() As Variant
ChaineATrouver = InputBox("Collez la chaine à rechercher")
Set DocEnCours = ActiveDocument
With DocEnCours
ReDim ListeDesParagraphes(.Paragraphs.Count - 1, 1)
IndexListe = 0
For I = .Paragraphs.Count To 1 Step -1
ListeDesParagraphes(IndexListe, 0) = I
If InStr(1, .Paragraphs(I).Range.Text, ChaineATrouver, vbTextCompare) > 0 Then
ListeDesParagraphes(IndexListe, 1) = "X"
End If
IndexListe = IndexListe + 1
Next I
End With
For IndexListe = LBound(ListeDesParagraphes, 1) To UBound(ListeDesParagraphes, 1)
If ListeDesParagraphes(IndexListe, 1) = "X" Then
Debug.Print ListeDesParagraphes(IndexListe, 0) & " : " & ListeDesParagraphes(IndexListe, 1)
End If
Next IndexListe
Set DocEnCours = Nothing
End Sub |
Partager