Is there a way to limit the number of lines per a word doc? RRS feed

  • Question

  • something like if lineCount >= 30 then insert a new page break ?

    I need to be able to set the number of lines per page. ( some line count limits I need are 30, 36, 60, etc )

    If no easy way like lineCount = 30

    Then I will check out the various ways that have occurred to me, to try.

    Like using ranges, of  RangeWholeDoc, RangeWholePage, RangeWholeSentence

    Looping thru ranges on page and checking if count of lines >= than what ever limit I have set.

    yes I do not know if enough functions are available to me to do it the above way.

    Another to try, move to end of each sentence, then try to get line count from word stats. if count >= lineLimit then insert new page break.

    I did consider using character count to tell when had reached >= lineLimit.   But NOT using mono-spaced font. so would be very hard to do.

    I did figure out how to in a user form, change paper size, margins, etc.  but still would have the problem of the number of lines would be affected by the Font Name and Font Size.

    Thank you for any info.

    Mark J

    Mark J

    Monday, May 29, 2017 10:16 AM

All replies

  • Hello,

    You could use the following code to get line count of the whole document and each page. Then you could check if it reaches the limitation and insert new page break.

    Sub Demo()
    Dim pn As Integer
    Dim ln As Integer
    ln = ActiveDocument.ComputeStatistics(wdStatisticLines, True)
    Debug.Print "There are " & ln & " lines in the document"
    pn = ActiveDocument.ComputeStatistics(wdStatisticPages, True)
    For i = 1 To pn
    Selection.GoTo What:=wdGoToPage, Which:=wdGoToAbsolute, Name:=i
    Debug.Print "There are " & Selection.Range.Information(wdFirstCharacterLineNumber) & " lines in Page" & i
    Next i
    End Sub



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Tuesday, May 30, 2017 7:29 AM
  • The simplest way, if your paragraphs use a consistent line spacing, is to adjust the top & bottom margins and/or paragraph line spacing to suit. No code required. Furthermore, adjusting the margins makes it very easy to vary the page line counts.

    Paul Edstein
    [MS MVP - Word]

    Wednesday, May 31, 2017 6:41 AM