End of document

W

WT

I have the following code and it works but unfortunately it won't do the
entire document because I don't know how to recognize the end of the file. I
have looked at the reference manuals but most only discuss how to modify the
last paragraph not how to determine when you get there and set an end to the
loop.

Please enlighten me ......

Dim rngParagraphs As Range, ststr(6), x, y
y = 100
x = 1
Do
'For x = x To y
Selection.HomeKey Unit:=wdLine
With ActiveDocument.Paragraphs(x).Range
.Select
End With
If (IsNumeric(Mid(ActiveDocument.Paragraphs(x).Range, 1, 1))) Then
x = x + 1
Else
With ActiveDocument.Paragraphs(x).Range
.Select
.Cut
.Collapse Direction:=wdCollapseEnd
End With
End If
'Next
Loop Until "eof ?????"
 
D

Doug Robbins - Word MVP

Tell us what you have and what you want to do with it.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
W

WT

I create a document with data from a database screen print.
I am formating and manipulating the data of which has no repeating
information.

What this routine does is look at the criteria and determine if the line
needs to be deleted or kept.

As stated before the code works but I have to use a for-next loop and give
it the number of lines to operate on. Since I generate documents of
different sizes they are never the same number of lines and I have to count
or guess the number.

What I would like, is to use a Do-loop and have it determine where the end
of the document is so that I can feed it any length document and not have to
have user intervention. Unfortunately since the document is already open I
can't use the "open file(1)" and then use the "EOF(1)" which probably would
be ideal but that is the only reference that I have found that actually
determines the end of file to stop a routine.

I am hoping you can find me something else that works just as
well........please
 
E

Ed from AZ

Might it work to check your paragraph range against the document
range?

Dim bolEOF As Boolean
If ActiveDocument.Paragraphs(x).Range.End = ActiveDocument.Content.End
Then bolEOF = True

Ed
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top