Move cursor to the last position

  • Thread starter Juan M Afan de Ribera
  • Start date
J

Juan M Afan de Ribera

Hi to everyone,

I need to move the cursor to the last position of a word document. By now, I
have found a way to do it and it seems to work

Dim r As Range

On Error Resume Next
Set r = ActiveDocument.Paragraphs(1).Range
r.Move wdParagraph, ActiveDocument.Range.Paragraphs.Count
r.Select
Set r = Nothing
On Error GoTo 0

but I am not sure that this is the correct one.

Any ideas?

TIA.

--
Access... también exiSte...!!

Saludos,
Juan M. Afán de Ribera
[MVP Access]
http://accessvbafaq.mvps.org
http://www.mvp-access.com/juanmafan
 
S

Stefan Blom

This would be a lot easier:

Selection.EndKey Unit:=wdStory

But note that a "correct" answer to your question depends on what you
are trying to do. If you moving the cursor in order to insert text at
the end of the document or modify paragraph properties of existing
text, you don't have to depend on cursor position/selections. For
example, you can access the properties of the final paragraph by
setting an object reference to it:

Dim mypara As Paragraph
Set mypara = ActiveDocument.Paragraphs.Last
With mypara
'code here
End With

--
Stefan Blom
Microsoft Word MVP


in message
news:[email protected]...
 
C

Cindy M -WordMVP-

Hi Juan,

There's often no single "correct" way to accomplish some tasks. In this
particular case, since you're setting the "selection", it perfectly legitimate
to work with it (instead of a range). Here's another way for you:

Selection.EndKey wdStory, false
I need to move the cursor to the last position of a word document. By now, I
have found a way to do it and it seems to work

Dim r As Range

On Error Resume Next
Set r = ActiveDocument.Paragraphs(1).Range
r.Move wdParagraph, ActiveDocument.Range.Paragraphs.Count
r.Select
Set r = Nothing
On Error GoTo 0

but I am not sure that this is the correct one.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 
J

Juan M Afan de Ribera

Thank you,

As Stefan said, I am trying to insert new text at the end of the document,
but before I need to read some things in the last paragraph. So, that code
for accessing the final paragraph will be very usefull. I think I can begin
from that point.

;-)

--
Access... también exiSte...!!

Saludos,
Juan M. Afán de Ribera
[MVP Access]
http://accessvbafaq.mvps.org
http://www.mvp-access.com/juanmafan
 

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