如何获取页面/章节开头



祝您愉快!我有一个Word文档和一个宏,它可以获取该文档的内容并将其插入另一个文档(具有所有边界、框架等(,基本上是无组织的。

我想检查一节(和任何一节(的第一页,看看是否有表格,如果有,退出循环,然后根据我们国家的文件标准相应地重新调整页面。我基本上没有检查新章节第一页的表格。

If objSection.Index = 1 Then 'the first section

'I need to check if there is a table on the first page of a section
Checking page size and orientation for the first Section.'(this is done)


ElseIf objSection.Index > 1 Then 'other sections

'practically the same thing, checking if a table exists on the first page of a section
Checking page size and orientation for all other Sections.'(this is also done)
End If

下面的内容应该会让您达到目的。

Function TableInFirstPageOfSection(sec As Section) As Boolean
Dim secRange As Range, secStart As Long
Dim tblRange As Range, tblStart As Long

TableInFirstPageOfSection = False
Set secRange = sec.Range
secRange.Collapse wdCollapseStart
secStart = secRange.Information(wdActiveEndPageNumber)
If sec.Range.Tables.Count > 0 Then
Set tblRange = sec.Range.Tables(1).Range
tblRange.Collapse wdCollapseStart
tblStart = tblRange.Information(wdActiveEndPageNumber)
If tblStart = secStart Then TableInFirstPageOfSection = True
End If
End Function

最新更新