Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 02-01-2024, 04:50 PM
Guessed's Avatar
Guessed Guessed is offline Macro Help - Search the last line of each page Windows 10 Macro Help - Search the last line of each page Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,185
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
 

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro Help - Search the last line of each page Macro to bold and center the first line of each page. MDom Word VBA 4 02-21-2023 09:43 PM
1st line of 4-line poem centrally aligned; how to get lines 2-4 to start at same location on page Swarup Word 6 09-16-2022 11:07 AM
Section and Line Break leaving line on previous page Stonehands99 Word 5 08-13-2019 08:59 PM
Macro Help - Search the last line of each page Page no's in Footer: p. "9" is one line higher than all other page no's: How to bring it down 1 line Swarup Word 24 12-30-2018 05:11 PM
Macro Help - Search the last line of each page macro to add brackets to each line and add single quotes to each word in the line bracketandquotes Word VBA 17 02-16-2015 03:51 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:52 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft