Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading