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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

End of text check & Scroll to top of the view

Status
Not open for further replies.

565u

Technical User
Apr 25, 2005
46
CZ
Hi!

Thanks for reading this. I have two problems I've been trying to solve for quite some time. If anybody smart can help me, that would be terrific.

-I am checking every paragraph for something. When done, I move to the next paragraph and so on... only I have no idea how to check for the end of the document. Anybody, please?

-I know how to scroll the text to the position of the cursor (should it be outside the screen), but I'd like to scroll so that the line with cursor is at the top of the screen - so that it is the very first line of text on the screen. Troubles me a lot.

Many thanks in advance for any kind advice!!


best regards,

pavel
 

Hi,

Each paragraph is an Object in the document
Code:
dim para as paragraph
for each para in activedocument.paragraphs

next
when yer outa para's, yer at the end of the document.

Skip,

[glasses] [red]A palindrome gone wrong?[/red]
A man, a plan, a ROOT canal...
PULLEMALL![tongue]
 
Thanks, but it doesn't work for me. I have probably should have written this: I start at any point in the text and then go thru the text, paragraph after paragraph, either up or down and check that paragraph for its outline level. So unfortunately your suggestion doesn't work :-( But it's a nice tip, thanks.
 


So if you're in paragraph 2 and there are 3 paragraphs in the document, that information does not mean anything?

Do you understand how ranges of text relate to paragraphs? So the last character in the last paragraph is the end of the document. Isn't that one of your questions?

Skip,

[glasses] [red]A palindrome gone wrong?[/red]
A man, a plan, a ROOT canal...
PULLEMALL![tongue]
 
I see you are touching a subject I don't know much about unfortunately. Of course knowing the number of all paragraphs in the file and the number of the paragraph with the insertion point/cursor would solve my problem :) I don't get it from your tip though. It seems to me it starts from the top of the document and goes down to the end. But what if I need to start from the current insertion point/cursor position? If I could read the number of paragraphs and the number of the current paragraph that would solve it. Could you kindly hi(n)t me a little bit more, please?
 

You need to familiarize yourself with the Word Object Model in VBA Help.

Search for help on Range.

I'm no Word VBA guru, so my specific suggestion are limited.

Skip,

[glasses] [red]A palindrome gone wrong?[/red]
A man, a plan, a ROOT canal...
PULLEMALL![tongue]
 
Hi 565u,

Skip is of course correct. It would help a lot to study the object model of Word.

Howver, if you could be a bit mor eclear on what exactly you want to do, perhaps I can help.

You want to do some sort of checking of paragraph, paragraph by paragraph, from any point in the document to the end of the document. Correct? Please state what else you are doing.

It is straightforward making a RANGE object that covers from the Selection to the end of the document. Just make its Start = the Selection Start, and its end = the doc end.
Code:
Sub HereToEnd()
Dim oRange As Word.Range
Dim oPara As Word.Paragraph
Set oRange = ActiveDocument.Range( _
    Start:=Selection.Range.Start, _
    End:=ActiveDocument.Range.End)

For Each oPara In oRange.Paragraphs
    ' whatever it is you are doing
    ' with the paragraphs
Next
   Set oRange = Nothing
End Sub

That being said, again, Skip is correct. To use VBA efficiently in Word, you need to really and truly grasp Range vs Selection.

What exactly are you doing?

Gerry
 
Thanks for your reply! I have actually managed to solve both problems thru some very nasty programming that works (but you can't be proud of it). Talking about it here helped a lot!!

Best regards!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top