Word 97 Macro - Loop to end of doc

Posted on 1998-05-27
Last Modified: 2008-02-01
I want to write a macro to do an action on each line of a document.

In older Words, you could do it with

How is one MEANT to do it in Word97.
I looked for a property such as
but that doesn't seem to exist.

(Whilst at it, how about end of section as well?)
Question by:sgb062497
  • 2
  • 2

Expert Comment

ID: 1606932

The words you are looking for are....




Hope this helps


Author Comment

ID: 1606933
These look like useful words. It still doesn't explain anywhere in the HELP that I can find WHAT to do with them.

I want to do something similar to the VB code below. It won't run this example because the While comparison is invalid.

Selection.HomeKey Unit:=wdStory
Selection.TypeText Text:="> "
Selection.EndKey Unit:=wdLine
While Selection.Range <> ActiveDocument.wdEndOfDocument
    Selection.MoveRight Unit:=wdCharacter, Count:=1
    Selection.TypeText Text:="> "
    Selection.EndKey Unit:=wdLine

I've also tried using
    While Not WdEndOfDocument
and that is valid but it never ends.

(If it matters, I'm in normal view rather than in Page layout view)

(The word help files are attrocious. You can't find out HOW to do anything, all you can do is find out something you already know about.)

=== sgb

Expert Comment

ID: 1606934
okay not quite sure if you want this for each pargraph or each line but for each paragraph you could do

for each aPara in ActiveDocument.Paragraphs


Author Comment

ID: 1606935
sorry about my last answer, submitted it and lost half of it!

Right now depends on if you want the text on a paragraph or a line basis, paragraphs are easier, but here should be the solutions or very close for both.

for paragraphs:

For Each apara In ActiveDocument.Paragraphs
   ActiveDocument.Range(Start:=apara.Range.End - 1, End:=apara.Range.End - 1).Select 'note the -1 so as not to move past the para mark
  Selection.TypeText ">"
Next apara

Now for Lines its a bit trickier but should be something like this

assuming you are at the line you want to start inserting from

While Selection.End < (ActiveDocument.StoryRanges(wdMainTextStory).End - 1) ' this will only do the body text
    Selection.EndKey Unit:=wdLine
    Selection.TypeText ">"
    Selection.Move Unit:=wdCharacter, Count:=1
Selection.TypeText ">"

Note if you have tables then you had better not try to insert any text on the end of row marker.  This can be ascertained by using :
 if Selection.Information (wdAtEndOfRowMarker) = true then 'this will mean it is at end of a table row.

Cheers Sparko


Accepted Solution

sparko earned 150 total points
ID: 1606936
Your methods seem to work.

I can hack them now to achieve what I really want.


=== sgb


Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Slide Show 5 96
Access 2013 won't install with Office 2016 (Home and Business) 8 25
PSTOOLS Office Activation Not Working 11 54
Office.Com /myAccount 9 38
Microsoft Office Picture Manager is not included in Office 2013. This comes as a shock to users upgrading from earlier versions of Office, such as 2007 and 2010, where Picture Manager was included as a standard application. This article explains how…
PaperPort has a feature called the "Send To Bar". It provides a convenient, drag-and-drop interface for using other installed software, such as Microsoft Office. However, this article shows that the latest Office 2016 apps (installed with an Office …
This video shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now