Get paragraphs in a separate part of a Word document

I have problems finding a specific section in a word. It was recommended that I try to search the VB Object Browser in Word for help. I know that there are at least 5 headings "sets" (IE, if you look in the Document Map, I see numbered 1,2,3,4,5 ...). I don’t know how to go to this fifth heading, initially I thought that these were sections, but when I looked at sections, I realized that almost all of this is in one section, but if someone is looking for information on how to make sections, it seems to work below since I already ran into a writing problem.

my($document) = $Word->Documents->Open($input) || die("Unable to open document ", Win32::OLE->LastError());
my $section = $document->{Sections}->Item(1); # put section number you're looking for in here
$section_five_paragraphs = $section->{Range}->Paragraphs();
$enumerate = new Win32::OLE::Enum($section_five_paragraphs); 
  while (defined($paragraph = $enumerate->Next()))
  {
     print $paragraph->{Range}->{Text} . "\n";
  }

So does anyone know how to get to this fifth header area, or can point me to something that might help?

+3
1

, , 1 ? , Word ( $document → {Sections} → Item (1)), . , . VBA ( perl) .

Sub FindHeading1()
    On Error GoTo MyErrorHandler

    Dim currentDocument As Document
    Set currentDocument = ActiveDocument

    Dim findRange As Range
    Set findRange = currentDocument.Sections(2).Range 'which section you want

    Dim endRange As Long
    endRange = findRange.end

    findRange.Find.ClearFormatting
    findRange.Find.Style = ActiveDocument.Styles("Heading 1")

    Dim headingCountFound As Long
    Do While findRange.Find.Execute(FindText:="")
        If findRange.End > endRange Then Exit Sub
        findRange.Select
        headingCountFound = headingCountFound + 1
        If headingCountFound = 3 Then 'which occurance you want
            MsgBox "Found."
            Exit Do
        End If

        DoEvents
    Loop

    Exit Sub

MyErrorHandler:
    MsgBox "FindHeading1" & vbCrLf & vbCrLf & "Err = " & Err.Number & vbCrLf & "Description: " & Err.Description
End Sub
+2

All Articles