none
Lines Per Page RRS feed

  • Question

  • Hi,

     

    Normally, when I open a new word document with default setting like:

     

    PageSetup

    ----------------------

    Paper A4 with "times new roman" "12"....

     

    I can write down 50 lines per page.

     

    But when i try to get the line numbers per page by using "ActiveDocument.PageSetup.LinesPage" it returns default 38 for

    A4...

     

    But I think that it must be 50....

     

    Why i need this information is that when the user changes the font from "12" to "11"  or "10" the line number per page

    increments by 5 in font "11" and it becomes 55 lines per page... I need to get line number per page dynamically...

     

    Thanks so much.

     

    Utku Selamoğlu

    Monday, February 25, 2008 2:48 PM

Answers

  •  Utku Selamoğlu wrote:

    Why i need this information is that when the user changes the font from "12" to "11"  or "10" the line number per page

    increments by 5 in font "11" and it becomes 55 lines per page... I need to get line number per page dynamically...

    There is nothing in the Word object model that will return this information. That's because the number of lines could differ depending on the content of the page. If it contains a table, or a graphic positioned in-line with the text, for example, the number of lines will differ. If various paragraph layout formatting is activated, lines of text may move to the next page for aesthetical reasons, and the page will not contain the maximum possible number of lines. Word "pages" are very dynamic, not static as in many Page Layout programs.

     

    The only "Line" objects in the object model have to do with graphical concepts, such as a line you'd draw on the page.

     

    You can calculate the number of lines on a specific page in a somewhat round-about manner, by

    - Turning on the Line Numbering

    - Making sure it restarts anew for each page

    - Retrieving the Line Number for the last line of text on the page

     

    Note, please, that this is only valid for a single page - other pages might contain more or fewer lines. If the page contains a table, the entire table is counted as one line, no matter how many rows or lines of text it may contain. The number returned will be the last line on the page, if the page is not full of text, the number returned will not represent the number of lines the page could contain.

     

    You'll find the Line Numbering functionality in the Page Setup dialog box. If you cannot find that, and want to experiment with it, you must tell us the version of Word you're using.

     

    Here's a code sample that will give you the Line Numbering count for the page currently selected in a document:

     

    Code Snippet
    Sub GetLastLineNumberOnCurrentPage()
        Dim doc As Word.Document
        Dim rng As Word.Range
        Dim curLineNumbering As Long
        Dim curSelection As Range
        Dim curPageNr As Long
        
        doc = wdAppActiveDocument
        'Preparation
        curLineNumbering = doc.PageSetup.LineNumbering.Active
        curSelection = wdApp.Selection.Range
        curPageNr = curSelection.Information(wdActiveEndPageNumber)
        wdApp.ScreenUpdating = False
       
        doc.PageSetup.LineNumbering.Active = True
        rng = doc.Bookmarks("\Page").Range
        rng.Collapse(Word.WdCollapseDirection.wdCollapseEnd)
        rng.Select()
        If rng.Information(Word.WdInformation.wdActiveEndPageNumber) <> curPageNr Then
            wdApp.Selection.MoveEnd Unit:=Word.WdUnits.wdLine, Count:=-1
        End If
        MsgBox wdApp.Selection.Information(wdFirstCharacterLineNumber)
       
        'clean up
        curSelection.Select()
        wdApp.ScreenUpdating = True
        doc.PageSetup.LineNumbering.Active = curLineNumbering
    End Sub

     

     


    Wednesday, July 30, 2008 2:40 PM
    Moderator

All replies

  • Hi,

     

    You are misundertanding of LinesPage property.

    See reference in MSDN:

    http://msdn2.microsoft.com/en-us/library/microsoft.office.interop.word.pagesetup.linespage(VS.80).aspx

    It returns or sets the number of lines per page in the document grid. You can make your document appears in grid view, and perform following Macro, you will find the linePage is lines' number of the grid, not your document text.

    Code Snippet

    Sub Test()
    Application.ActiveDocument.PageSetup.LinesPage = 20
    End Sub

     

     

    In fact, each line can has his own font size. How can we expect a common property to get the lines number?

    But I think you can use Application.Selection.Goto(), SendKeys({"DOWN"}), Application.Selection.Information and some logic to get how many lines exist in a specific page.

     

     

    Thanks,

    Ji

    Wednesday, February 27, 2008 1:58 PM
    Moderator
  •  

    Hi,

    Could you please help in the below scenerio

     

    how can i get the distance between two text in a document.

     

    Thanks,

    Ravi Neelam

    Wednesday, July 30, 2008 10:08 AM
  •  Utku Selamoğlu wrote:

    Why i need this information is that when the user changes the font from "12" to "11"  or "10" the line number per page

    increments by 5 in font "11" and it becomes 55 lines per page... I need to get line number per page dynamically...

    There is nothing in the Word object model that will return this information. That's because the number of lines could differ depending on the content of the page. If it contains a table, or a graphic positioned in-line with the text, for example, the number of lines will differ. If various paragraph layout formatting is activated, lines of text may move to the next page for aesthetical reasons, and the page will not contain the maximum possible number of lines. Word "pages" are very dynamic, not static as in many Page Layout programs.

     

    The only "Line" objects in the object model have to do with graphical concepts, such as a line you'd draw on the page.

     

    You can calculate the number of lines on a specific page in a somewhat round-about manner, by

    - Turning on the Line Numbering

    - Making sure it restarts anew for each page

    - Retrieving the Line Number for the last line of text on the page

     

    Note, please, that this is only valid for a single page - other pages might contain more or fewer lines. If the page contains a table, the entire table is counted as one line, no matter how many rows or lines of text it may contain. The number returned will be the last line on the page, if the page is not full of text, the number returned will not represent the number of lines the page could contain.

     

    You'll find the Line Numbering functionality in the Page Setup dialog box. If you cannot find that, and want to experiment with it, you must tell us the version of Word you're using.

     

    Here's a code sample that will give you the Line Numbering count for the page currently selected in a document:

     

    Code Snippet
    Sub GetLastLineNumberOnCurrentPage()
        Dim doc As Word.Document
        Dim rng As Word.Range
        Dim curLineNumbering As Long
        Dim curSelection As Range
        Dim curPageNr As Long
        
        doc = wdAppActiveDocument
        'Preparation
        curLineNumbering = doc.PageSetup.LineNumbering.Active
        curSelection = wdApp.Selection.Range
        curPageNr = curSelection.Information(wdActiveEndPageNumber)
        wdApp.ScreenUpdating = False
       
        doc.PageSetup.LineNumbering.Active = True
        rng = doc.Bookmarks("\Page").Range
        rng.Collapse(Word.WdCollapseDirection.wdCollapseEnd)
        rng.Select()
        If rng.Information(Word.WdInformation.wdActiveEndPageNumber) <> curPageNr Then
            wdApp.Selection.MoveEnd Unit:=Word.WdUnits.wdLine, Count:=-1
        End If
        MsgBox wdApp.Selection.Information(wdFirstCharacterLineNumber)
       
        'clean up
        curSelection.Select()
        wdApp.ScreenUpdating = True
        doc.PageSetup.LineNumbering.Active = curLineNumbering
    End Sub

     

     


    Wednesday, July 30, 2008 2:40 PM
    Moderator