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
-
本文介绍了一个VBA函数,用于确定Word文档中指定页面所在的节编号。通过使用ActiveDocument.GoTo方法定位到特定页,再通过Sections属性获取该页所在的节编号。此外,还提供了一个测试子程序来验证函数的正确性。
8053

被折叠的 条评论
为什么被折叠?



