Jeffrey Bradshaw said:
Is there a way in VB.NET to find out how many pages are in a section? I
assume I could select the section and then count the number of times the
bookmark \page appears but I was wondering if there is an easier way.
Hi, Jeffrey,
This is in VBA, but the conversion to VB.Net isn't too difficult.
Public Sub SectionPages()
Dim oRg As Range
Dim StartPg As Long, EndPg As Long
Set oRg = Selection.Sections(1).Range
With oRg
.Collapse wdCollapseStart
StartPg = .Information(wdActiveEndPageNumber)
End With
Set oRg = Selection.Sections(1).Range
With oRg
.Collapse wdCollapseEnd
' it's now at the first char of
' the next section -- move back
.Move wdCharacter, -1
EndPg = .Information(wdActiveEndPageNumber)
End With
MsgBox "Section contains " & _
EndPg - StartPg + 1 & " page(s)" & vbCr & _
"(" & StartPg & "-" & EndPg & ")"
End Sub
In VB.Net, you need to know that the wdXX constants are
Word.WdInformation.wdActiveEndPageNumber and Word.WdUnits.wdCharacter.
Also, I suspect you want to interrogate some specific section number
nSection, so set oRg to wdDoc.Sections.Item(nSection).Range instead of
Selection.Sections(1).Range.