Reputation: 542
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
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:
Upvotes: 0