Results 1 to 4 of 4
  1. #1
    4 Star Lounger
    Join Date
    Jan 2002
    Location
    London, Gtr London, England
    Posts
    416
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Selecting/setting last page as range (All)

    Hi

    Is it possible to select/set the contents of the last page as a *range* without *selecting*/going to the last page? This is how I do it at the moment & even with screenupdating to false, the display still goes to the last page.

    Application.ScreenUpdating = False
    Selection.GoTo what:=wdGoToPage, which:=wdGoToLast
    Set myRange = ActiveDocument.Content
    ' myRange.GoTo what:=wdGoToPage, which:=wdGoToLast
    myRange.SetRange Start:=Selection.Start, End:=ActiveDocument.Content.End
    Thanks.
    Robie

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Selecting/setting last page as range (All)

    I don't think so - Word doesn't really "think" in terms of pages. There is no Pages collection in the Word VBA model.

    You can do the following:

    Selection.EndKey Unit:=wdStory
    Set MyRange = ActiveDocument.Bookmarks("Page").Range

    Page is a predefined bookmark that refers to the current page - look up "predefined bookmarks" in the Word VBA help if you want to know more about them.

  3. #3
    4 Star Lounger
    Join Date
    Jan 2002
    Location
    London, Gtr London, England
    Posts
    416
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Selecting/setting last page as range (All)

    Thanks Hans - I will try it out.
    Thanks.
    Robie

  4. #4
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Re: Selecting/setting last page as range (All)

    You can try this rather basic bit of code. The cursor stays still, and you'll get the contents of the last page. You could use wdCharacter instead of wdWord if there's a chance that the last page begins with a portion of a hyphenated word. There's a bit of a speed hit.

    Sub GetTextLastPage()
    Dim lPage As Long
    Dim rng As Range
    Dim rng1 As Range
    Dim rng2 As Range
    With ActiveDocument
    Set rng = .Paragraphs(.Paragraphs.Count).Range
    Set rng1 = rng.Duplicate
    lPage = rng.Information(wdActiveEndPageNumber)
    Do Until rng1.Information(wdActiveEndPageNumber) <> lPage
    rng1.Move unit:=wdWord, Count:=-1
    rng1.Collapse wdCollapseStart
    Loop
    rng1.Move unit:=wdWord, Count:=1
    Set rng2 = .Range(start:=rng1.start, End:=rng.End)
    End With
    MsgBox rng2.Text
    End Sub

Posting Permissions

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