View Single Post
 
Old 02-01-2024, 04:50 PM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,176
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Do you mean LINE or PARAGRAPH? It is highly likely that the last character on any given page is either a space or a paragraph mark although the last character you can see might be a ")"
This code does what you asked for (but perhaps not what you meant). I've dealt with a trailing space but not with a trailing paragraph mark.
Code:
Sub LastLiner()
  Dim aRng As Range, rngPage As Range, rngLine As Range, sText As String
  Set rngPage = ActiveDocument.Bookmarks("\Page").Range
  Do While rngPage.End + 1 < ActiveDocument.Range.End
    rngPage.MoveEnd Unit:=wdCharacter, Count:=-1
    rngPage.Collapse Direction:=wdCollapseEnd
    rngPage.Select
    Set rngLine = ActiveDocument.Bookmarks("\Line").Range
    rngLine.Select
    sText = Trim(rngLine.Text)
    If sText Like "BY*" Or sText Like "EXAMINATION*" Or sText Like "*)" Then
      Exit Do
    Else
      Selection.Collapse Direction:=wdCollapseEnd     'moves selection to top of next page
      Set rngPage = ActiveDocument.Bookmarks("\Page").Range
    End If
  Loop
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote