Results 1 to 4 of 4
  1. #1
    New Lounger
    Join Date
    Sep 2001
    Location
    Springfield, Illinois, USA
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Count words (Word2000SP2)

    I have a Word document that must be printed in 10 pt and must print on one page. It has 2 sections that have variable data that might end up pushing it onto 2 pages. It is already margin to margin and I basically have 3 extra lines available before it goes to page 2. What I'm wondering is if there is a way to count the total number of lines on the page, so that I can catch this when it happens.

    Thanks!
    Dianne

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Count words (Word2000SP2)

    You could change the print behavior by having it check the number of pages and alert you if there is more than one page: "Document exceeds one page. Print anyway? Yes/No"

    If you want to know the instant the document gets too long, though, it could be much more complicated to program.

  3. #3
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Count words (Word2000SP2)

    If you have a range that starts on the last line of the document then you can use
    <code> rng.Information(wdFirstCharacterLineNumber)</code>

    If you haven't got a range already then
    <code> Set rng = ActiveDocument.Content
    rng.Collapse direction:=wdCollapseEnd</code>

    StuartR

  4. #4
    3 Star Lounger
    Join Date
    Apr 2004
    Location
    Boston, Massachusetts, USA
    Posts
    389
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Count words (Word2000SP2)

    For some reason, I found this particular problem very intriguing. The danger in counting line numbers is that you may later decide to change the margins or space between paragraphs. How about instead see if the end of the document is on the first page. If not, then the document is more than one page long. You could use this test before printing, before saving, or whenever.

    The second version is just me being silly and realizing I could make an obnoxiously long single line of code ...

    <pre>Function IsDocOnlyOnePage() As Boolean
    Dim doc As Document
    Dim rngOrigSelection As Range
    Dim rngEndOfDoc As Range
    Dim rngPage As Range
    Dim lngEnd As Long

    Set doc = ActiveDocument
    Set rngOrigSelection = Selection.Range.Duplicate

    lngEnd = doc.Range.End
    Set rngEndOfDoc = doc.Range(lngEnd - 2, lngEnd - 2)
    Set rngPage = doc.Bookmarks("page").Range

    doc.Range(0, 0).Select

    IsDocOnlyOnePage = rngEndOfDoc.InRange(rngPage)

    rngOrigSelection.Select
    End Function
    '
    ' And a slightly more obfuscated version ...
    '
    Function IsDocOnlyOnePageObfuscatedVersion() As Boolean
    ActiveDocument.Range(0, 0).Select
    IsDocOnlyOnePageObfuscatedVersion = _
    ActiveDocument.Range(ActiveDocument.Range.End - 2, _
    ActiveDocument.Range.End - 2).InRange(ActiveDocument.Bookmarks("page").Range)
    End Function
    </pre>


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •