none
Insert a Page break in Word RRS feed

  • Question

  • Hi Hans Vogelaar,

    I would like to insert a page break in a MS Word where ever I found a word 'PAGE' either in even/odd page.

    I'm using a table also in the MS Word, it should check those tables also. And it should replace the word with page break.

    Can you please help me to resolve this issue. 

    Thanks,

    AVN

    Friday, October 9, 2015 7:15 AM

Answers

  • >>>Actually my requirement is in a word, if I found a string/word as Table:3, It should be replaced with 'Page Break'. So that the next table can be seen in next table.

    According to your description, I have made a sample and tested Hans Vogelaar's VBA code, and It's working.

    These are sample code:

    Sub InsertPageBreaks()
    
         Application.ScreenUpdating = False
         Selection.HomeKey Unit:=wdStory
    
         With Selection.Find
             .ClearFormatting
             .Text = "Table:3"
             .MatchCase = True
             Do While .Execute
                 Selection.Delete
                 Selection.InsertBreak Type:=wdPageBreak
             Loop
         End With
         Application.ScreenUpdating = True
    
     End Sub
    

    Wednesday, October 14, 2015 8:34 AM
  • Hi AVN

    A couple of observations:

    1) You can't insert a page break IN a table. You can insert a page break that will break the table into two different tables, one ending on one page, the other starting on the next page.

    2) The code works in all versions of Word since Word 97; it doesn't matter whether a docx or a doc file.

    If your problem is that a ROW should not break across pages, then you can coerce that with formatting: deactivating the Table option to allow rows to break across pages.


    Cindy Meister, Office Developer/Word MVP, <a href="http://blogs.msmvps.com/wordmeister"> my blog</a>

    Thursday, October 15, 2015 2:46 PM
    Moderator

All replies

  • If you activate the Replace dialog (press Ctrl+H), you can enter PAGE in the Find What box and ^m in the Replace With box, you can replace all instances of PAGE with a page break except those in tables. To process occurrences in tables too, you can use the following macro:

    Sub InsertPageBreaks()
        Application.ScreenUpdating = False
        Selection.HomeKey Unit:=wdStory
        With Selection.Find
            .ClearFormatting
            .Text = "PAGE"
            .MatchCase = True
            Do While .Execute
                Selection.Delete
                Selection.InsertBreak Type:=wdPageBreak
            Loop
        End With
        Application.ScreenUpdating = True
    End Sub


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    Friday, October 9, 2015 10:16 AM
  • Hi, 

    Thanks for your reply, but it was not working.

    Table:1

    Table:2

    Table:3

    Actually my requirement is in a word, if I found a string/word as Table:3, It should be replaced with 'Page Break'. So that the next table can be seen in next table.

    Thanks,

    AVN

    Monday, October 12, 2015 9:22 AM
  • >>>Actually my requirement is in a word, if I found a string/word as Table:3, It should be replaced with 'Page Break'. So that the next table can be seen in next table.

    According to your description, I have made a sample and tested Hans Vogelaar's VBA code, and It's working.

    These are sample code:

    Sub InsertPageBreaks()
    
         Application.ScreenUpdating = False
         Selection.HomeKey Unit:=wdStory
    
         With Selection.Find
             .ClearFormatting
             .Text = "Table:3"
             .MatchCase = True
             Do While .Execute
                 Selection.Delete
                 Selection.InsertBreak Type:=wdPageBreak
             Loop
         End With
         Application.ScreenUpdating = True
    
     End Sub
    

    Wednesday, October 14, 2015 8:34 AM
  • Hi David,

    Thanks for reply, the code which you mentioned is used to insert the page break in a word format. But if I'm using the table in the doc file then it won't work.

    I need to insert the page break inside the table.

    Thanks for your suggestion David. 

    Thanks,

    AVN

    Thursday, October 15, 2015 6:55 AM
  • Hi AVN

    A couple of observations:

    1) You can't insert a page break IN a table. You can insert a page break that will break the table into two different tables, one ending on one page, the other starting on the next page.

    2) The code works in all versions of Word since Word 97; it doesn't matter whether a docx or a doc file.

    If your problem is that a ROW should not break across pages, then you can coerce that with formatting: deactivating the Table option to allow rows to break across pages.


    Cindy Meister, Office Developer/Word MVP, <a href="http://blogs.msmvps.com/wordmeister"> my blog</a>

    Thursday, October 15, 2015 2:46 PM
    Moderator
  • Hi Cindy,

    Thanks for your reply.

    Can you please provide me the code for 'insert a page break that will break the table into two different tables'.

    Thanks,

    AVN

    Friday, October 16, 2015 6:59 AM
  • David's code demonstrates that - there's a line in it that inserts a page break.

    Cindy Meister, Office Developer/Word MVP, <a href="http://blogs.msmvps.com/wordmeister"> my blog</a>

    Friday, October 16, 2015 6:12 PM
    Moderator