?
Solved

Word 97 Macro - Loop to end of doc

Posted on 1998-05-27
5
Medium Priority
?
769 Views
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
WHILE CMPBOOKMARKS (\sel, \EndofDoc))
....
WEND

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

(Whilst at it, how about end of section as well?)
0
Comment
Question by:sgb062497
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 3

Expert Comment

by:frazer
ID: 1606932
Hi,

The words you are looking for are....

WdEndOfDocument

and

WdEndOfSection

Hope this helps

Frazer
0
 

Author Comment

by:sgb062497
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
Wend

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
0
 
LVL 1

Expert Comment

by:sparko
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


0
 

Author Comment

by:sgb062497
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
Wend
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










0
 
LVL 1

Accepted Solution

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

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

Thanks

=== sgb

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

771 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