Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 02-01-2024, 11:35 AM
Donovahkiin Donovahkiin is offline Macro Help - Search the last line of each page Windows 10 Macro Help - Search the last line of each page Office 2016
Novice
Macro Help - Search the last line of each page
 
Join Date: Oct 2023
Posts: 4
Donovahkiin is on a distinguished road
Question Macro Help - Search the last line of each page

Hello! I'm trying to write a macro that will search the last line of each page and tell me if it contains certain text. I'm having trouble. I wish the Page object would just have a .Next feature like Paragraph does...

Do you know an easy way to iterate through each page like that? My pages for transcription work are always 25 lines, so I tried moving the cursor down that many lines each loop as a workaround. But then if there was an indent earlier, it keeps that spacing on later pages instead of looking at the start of the line.

Here's what I have so far, and I can tell you what's wrong with it.

Code:
Sub WIPSearchLastLine()
    Dim aPage As Page
    On Error Resume Next
    For Each aPage In ActiveDocument.ActiveWindow.Panes(1).Pages
        Selection.MoveDown Unit:=wdLine, Count:=24
        If Selection.Range.Next.Characters(2).Text = "BY" Then
            Selection.Next.HighlightColorIndex = wdBrightGreen
        End If
        Selection.MoveDown
    Next aPage
End Sub
Problems:
- My "If" block always resolves as True. I know that's wrong, but I'm not sure why that is.
- I have to manually click my cursor to the start of the first page before running.
- It doesn't check the first characters in the last line, it's highlighting a handful of characters later relative to what indentation was on earlier pages.
- If the last line of a page is blank or short, it highlights the beginning of the line on the next page instead.

Full scope of project:


* For the last line of each page:
- If it starts with "BY" or starts with "EXAMINATION" or ENDS with a closing parenthesis ")"
- Bring it to my attention. Ideally, move the cursor there and just exit the program. So I can fix that line, then re-run the program. I just had it highlight so it's more obvious what my program's doing.

Any help I can get with this would be wonderful.
Reply With Quote
 



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 09:23 PM.


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