Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to check if current paragraph/line is the last?

Status
Not open for further replies.

565u

Technical User
Apr 25, 2005
46
CZ
Hi and thanks for reading my post. This is something I have been working around for years and it's been always very difficult and cumbersome. I just cannot figure out (in vb 6.3) how to find out whether the current (where the insertion point is) paragraph or line is the last in the document. I need to stress that I don't need to do "something" to every paragraph in the document. But often I need to do something to every paragraph or line from the insertion point till the end of the document and I have no idea how to check whether I have already reached it or not.

Could anybody kindly help me please?


Best regards,


Pavel
 
First of all, this is the VBA forum, not the VB forum. Although in this case the differences are not all that relevant.

Second, I am not sure exactly what you are asking.

Are you using Ranges? If so, then:
Code:
Dim r As Word.Range
Set r = ActiveDocument.Range(Start:=Selection.Range.End, _
    End:=ActiveDocument.Range.End)
will set a Range object for everything from the Selection (the end of the Selection) to the end of the document. You can perform actions on that Range.

If it is for some kind of action performed on all the paragraph from the Selection to the end of the document (regardless of the number of paragraphs), then I would not bother even trying to determine if it is the last of not.
Code:
Dim r As Word.Range
Dim oPara As Paragraph
Set r = ActiveDocument.Range(Start:=Selection.Range.End, _
    End:=ActiveDocument.Range.End)
For Each oPara In r.Paragraphs
  ' do stuff
Next
uses a Paragraph object to action every paragraph from the Selection End point to the end of the document.

It does not matter if there is 2, or 200 paragraphs. It simply actions them all. It does not need to know if the action is on the last one..it actions them all.

So, um, could you clarify what it is you want to know?
Are you actually trying to find out if the Selection is in the last paragraph? Is this as a Boolean?

In last paragraph = True? In last paragraph = False?

Gerry
My paintings and sculpture
 
Thank you very much! Problem solved :)
Best regards,
Pavel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top