TJ87
TJ87

Reputation: 542

How do I insert a page break after every table in a document?

new VBA user here. I have an MS Word document with 30 tables that I created outside of Office. I would like to insert a page break after every table in the document. I tried this VBA macro to insert the break at every paragraph as a placeholder for the table:

Sub InsertBreak()
Set myRange = ActiveDocument.Paragraphs(2).Range
With myRange
 .Collapse Direction:=wdCollapseEnd
 .InsertBreak Type:=wdPageBreak
End With
End Sub   

This just adds one page break before the first table in the doc. I would like to insert page breaks at every table (paragraph) starting from the second not the first. Thanks.

Upvotes: 0

Views: 472

Answers (1)

taller
taller

Reputation: 18963

Option Explicit
Sub InsertPgBreak()
    Dim i As Long
    For i = 2 To ActiveDocument.Tables.Count
        ActiveDocument.Tables(i).Range.InsertBreak Type:=wdPageBreak
    Next i
End Sub

Microsoft documentation:

Selection.InsertBreak method (Word)

Upvotes: 0

Related Questions