[Solved] Get the chapters under which an occurrence of a word is in the document in Word VBA [closed]


I finally found another way to do this. I loop on the paragraphs :

For Each objPara In Selection.Paragraphs
    With objPara.Range
        sText = .Text
        sStyle = .ParagraphStyle

        'On détermine le style de l'élément courant s'il en a un
        If sStyle = "Titre 1;H1" Then
            If sH1 <> sText Then
                sH2 = ""
            End If
            sH1 = sText
        ElseIf sStyle = "Titre 2;H2" Then
            If sH2 <> sText Then
                sH3 = ""
            End If
            sH2 = sText
        ElseIf sStyle = "Titre 3;H3" Then
            sH3 = sText
        End If
        Set regMatch = RegEx.Execute(sText)
        IsAMatch = (regMatch.Count > 0)
        If IsAMatch Then
            'PATH de l'exigence
            sPath = sH1
            If sH2 <> "" Then
                sPath = sPath & "https://stackoverflow.com/" & sH2
            End If
            If sH3 <> "" Then
                sPath = sPath & "https://stackoverflow.com/" & sH3
            End If
        End If
    End With
Next

solved Get the chapters under which an occurrence of a word is in the document in Word VBA [closed]