分页符后定位插入点

时间:2019-01-28 10:51:57

标签: vba ms-word

我正在使用VBA构建包含一系列表格的Word文档。在某些表格之后,我想插入一个分页符,然后在下一页继续一个新表格。我的代码添加了一个分页符,但是插入点移到了文档的顶部,因此下一个表最终嵌套在第一个表的第一个单元格内。

Dim workRange As Word.Range

Set HeaderTableId = WordDoc.Tables.Add(Range:=wrdSel.Range, numcolumns:=3, numrows:=1, AutoFitBehavior:=wdWord9TableBehavior)
' (code to add rows goes in here)
Set workRange = HeaderTableId.Range
With workRange
    .Collapse WdCollapseDirection.wdCollapseEnd
    .InsertAfter vbCr 
    .Collapse WdCollapseDirection.wdCollapseEnd
End With
' (This correctly separates the next table from the previous one)

Set WarningsTableId = WordDoc.Tables.Add(Range:=workRange, numcolumns:=1, numrows:=1, AutoFitBehavior:=wdWord9TableBehavior)
Set RowId = WarningsTableId.Rows.Add
' (code to add rows goes in here)
Set workRange = WarningsTableId.Range
With workRange
    .Collapse (WdCollapseDirection.wdCollapseEnd)
    .InsertAfter vbCr 
    .Collapse WdCollapseDirection.wdCollapseEnd
End With
' Finally, nothing more needed on this page, so insert a page break
With workRange
    .Collapse (WdCollapseDirection.wdCollapseEnd)
    .InsertBreak (WdBreakType.wdPageBreak)
    .Collapse WdCollapseDirection.wdCollapseEnd 
End With
' The processs then loops back to the top to add a new HeaderTable,
' but the new table appears nested within the first cell of the first HeaderTable.

0 个答案:

没有答案