Word VBA - Move cursor to start of current paragraph but don't move it if it is already there

I want to move the cursor to the start of the current paragraph. If I do the normal

    Selection.MoveUp Unit:=wdParagraph, count:=1

the cursor goes to the start of the current paragraph, unless it is already there, in which case it moves to the beginning of the previous paragraph.  How do I prevent it from doing that, ie don't move it if it's already at the start of the paragraph.
Answer
Answer
Learn to love ranges :)

Dim oRng As Range
Set oRng = Selection.Paragraphs(1).Range
oRng.Collapse wdCollapseStart
oRng.Select

... Learn to love simplicity :)

  Selection.MoveRight Unit:=wdCharacter, Count:=1
  Selection.MoveUp Unit:=wdParagraph, Count:=1

That is, move one pos to the right and then at start of the para.

It works even if the cursor is at the end of the para

Alkis

12 people found this reply helpful

·

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

 
 

Question Info


Last updated June 27, 2024 Views 14,152 Applies to: