In a macro or global search how do you test for the end of the document?
If this subject is in the archives please give me words or phrases to search on. End of document generated hits but nothing I could use.
Thanks
![]() |
There are isolated problems with current patches, but they are well-known and documented on this site. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
Home » Forums » AskWoody support » Productivity software by function » MS Word and word processing help » Test for End of Document (Word 97)
There are several methods, but you need to describe the scenario in more detail.
Suppose, for example, that you want to repeat an action over and over but stop when your insertion point is in front of the last paragraph mark in the body. You know you’re there when the insertion point position is one less than the last position in the text:
While Selection.End < ActiveDocument.Content.End – 1
'Do Stuff
Wend
But… if you are using Find, using these settings should stop at the end of the document
With Selection.Find
…
.Forward = True
.Wrap = wdFindStop
Does this help?
In other words, you want to know if your insertion point is on the last line of a document, anywhere in the line? Mmmm… not immediately obvious.
Why are using using wdLine? Do you really have to? If you were to use wdParagraph, then the test I posted before should work. Hopefully it’s not too lazy of me to suggest this approach.
Yes, I do want to know if the insertion point is on the last line of a document.
I normally program in Access 97 and import a text file into a table. Normally the file is single-spaced, but for some unknown reason once every three months the file comes over double-spaced.
I used the macro builder in Word 97 to move down one line and delete the extra line. That is where wdLine came from. I really can’t answer questions as to why I would use one command over another and I may not be using the correct terminology. I defer to you and others on this list with more experience to point me in the right direction.
Thanks
When the global replace has failed for me it is usually due to
1. Some other character in between (space, tab, floating graphic)
2. Revision tracking
3. The return is actually a ^13 character
4. More than two consecutive returns – solved by running the replace multiple times or using wildcards to search for two or more returns.
So it doesn’t surprise me that the global replace is not fully consistent for you but you may find your code will stumble over the same issues.
Andrew’s #3 is common in text that was not created in Word for Windows, as other programs and platforms often have a different view on how to end a line. Since Word will find a ^p when you search for a ^13 (note: thirteen, not L3) and not the other way around, it should be equally effective to:
Find: ^13^13
Replace: ^p
in your scenario.
One way of learning what those different “Unit” codes mean is to turn on the macro recorder and navigate around. MoveDown wdLine is roughly the same as DownArrow, while MoveDown wdParagraph is roughly the same as Ctrl+DownArrow. The first works well in structured data, but the second is more reliable if you want to go to the beginning of the next line (where the current line ends with a paragraph mark).
Anyway, for your purposes, I completely agree with the Find and Replace approach. Use the More button to reveal the special characters pop-up and you’ll see the incredible flexibility available to you.
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
S | M | T | W | T | F | S |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.
Notifications