# inserting page break using a macro



## anjali5 (Jan 20, 2013)

I want to write a macro in MS word that insert page break in the ms word document where ever there is a sentence called 
----PAGE BREAK--- in the word document

I have around 200 page word document where there are at least 100 PAGE BREAK sentences in the document. I want the macro that inserts the page break wherever the PAGE BREAK sentence is seen.
Also, I want to write "THIS IS A DRAFT DOCUMENT" as the HEADER and FOOTER for the entire document.


----------



## AlbertMC2 (Jul 15, 2010)

Hi

Try this:

```
Sub test()

    Dim i As Long
    
    With Selection.Find
        .ClearFormatting
        .Text = "----PAGE BREAK---"
        .Replacement.ClearFormatting
        .Replacement.Text = "^m"
        .Execute Replace:=wdReplaceAll, Forward:=True, Wrap:=wdFindContinue
    End With

    For i = 1 To ActiveDocument.Sections.Count
        With ActiveDocument.Sections(i)
            .Headers(wdHeaderFooterPrimary).Range.Text = "THIS IS A DRAFT DOCUMENT"
            .Footers(wdHeaderFooterPrimary).Range.Text = "THIS IS A DRAFT DOCUMENT"
        End With
    Next

End Sub
```


----------



## anjali5 (Jan 20, 2013)

For inserting page breaks, I wrote the excat code that you gave me, but it didn't work. Do I need to turn on the wild card option in Ms word. i am using MS word 2007.

This is what I have and I replaced this code with the code that you gave me, but still could not insert Page Breaks

With Selection.Find
.Text = "-- PAGE Break --"
.Replacement.Text ="^m"
.Forward=True
.Wrap = wdFindContinue
.Format = False
.MatchCase=False
.MatchWholeWord= False
.MatchWildCards=True
.MatchSoundsLike=False
.MatchAllWordForms=False
END WITH

any help will be greatly apprecaited.


----------

