VBA 怎么得到WORD文档指定页处于第几节?
Function SectionNumber(PageNumber As Long) As Long
Dim myRange As Range
Set myRange = ActiveDocument.GoTo(what:=wdGoToPage, which:=wdGoToAbsolute, Count:=PageNumber)
SectionNumber = myRange.Sections(1).Index
End Function
可用以下过程进行测试:
-
VB code
-
Sub Test() Dim lCount As Long , i As Long lCount = ActiveDocument.ActiveWindow.Panes( 1 ).Pages.Count For i = 1 To lCount Debug.Print " Page: " & i & " , Section: " & SectionNumber(i) Next i
-