Results 1 to 2 of 2

Thread: print last 20 lines

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2006
    Posts
    39

    print last 20 lines

    I need to print the last twenty lines of various word documents. Can someone help me to accomplish this?

    I would like to create a macro that will just print out the last 20 lines of the open document. I don't need to save anything. This is just for reference purposes.

  2. #2
    Addicted Member sweet_dreams's Avatar
    Join Date
    Apr 2005
    Location
    Poland, Lodz
    Posts
    189

    Re: print last 20 lines

    hi Wooonelly,

    Paste this code into a new module:

    VB Code:
    1. Sub Select20Lines()
    2. Dim lines_no As Long
    3. Dim text_selection As Selection
    4.  
    5. lines_no = ActiveDocument.ComputeStatistics(wdStatisticLines)
    6.  
    7. If lines_no < 20 Then
    8.     MsgBox "Not enough lines to select!"
    9.     Exit Sub
    10. End If
    11.  
    12. Selection.GoTo wdGoToLine, wdGoToAbsolute, (lines_no - 19)
    13. Selection.Expand wdLine
    14. Selection.MoveEnd wdLine, 19
    15.  
    16. ActiveDocument.PrintOut , , wdPrintSelection
    17.  
    18. End Sub

    This code selects 20 last lines in document and prints it. Hope it is what you needed.

    regards,
    sweet_dreams
    using VB 2010 .NET Framework 4.0; MS Office 2010; SQL Server 2008 R2 Express Edition | Remember to mark resolved threads and rate useful posts.

Posting Permissions

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



Click Here to Expand Forum to Full Width