Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MS Word Macro Remove Blank Lines Before a page break

Status
Not open for further replies.

dodge20

MIS
Jan 15, 2003
1,048
US
I currently have a macro that finds text and places a page break in front of it, which works fine. The problem is I have a variable number of blank lines before each page break. I would like that variable number to be 3. Currently I am doing a find replace many times and replacing
^p^p^p^p
with
^p^p^p

I am wondering if there is a way to loop through the word document to perform this instead of me doing a find and replace 20+ times?

My macro to insert the page break is

Code:
Dim strData As String
strData = InputBox("Paste Text where you want the page break inserted")
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = (strData)
        .Replacement.Text = "^m" & (strData)
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    ActiveWindow.ActivePane.VerticalPercentScrolled = 0
End Sub

Dodge20
 



Hi,

"I would like that variable number to be 3."

Read your statement carfully as see the contradiction.

I would urge you to use Word's Styles feature to control white spece in your document. Multiple adjacent paragraphs are not a best and accepted method.

As I stated in your original thread, You can loop to replace ^p^p with ^p until no replacement takes place.

This as modified from HELP
Code:
    With ActiveDocument.Content.Find
        Do While .Execute(FindText:="^p^p", Forward:=True, _
                Format:=True, ReplaceWITH:="^p", Wrap:=wdFindContinue) = True
        Loop
    End With

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
What about this pattern ?
^p{3,}

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top