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

Moving Text and returning the cursor

Status
Not open for further replies.

poppingpowpoof

Technical User
Feb 4, 2009
2
US
I am sure this is a simple problem but need some direction. I have a To Do Word document and when I complete a task I want to move the entire line to the bottom of the document by starting a macro. I can move the text but how do I get the cursor back to where I started?

Here is what I have so far--and thanks for your patience with this newbie!

Sub moveline()
'
' moveline Macro
'
'
Selection.MoveDown Unit:=wdLine, Count:=1, Extend:=wdExtend
Selection.Cut
Selection.EndKey Unit:=wdStory
Selection.PasteAndFormat (wdPasteDefault)
End Sub
 



Hi,

How about inserting a bookmark where you want to return, before moving the text?

Skip,
[glasses]Don't let the Diatribe...
talk you to death![tongue]

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Can you be a bit more specific? It seems to you wish to move the text. Is this correct? Assuming you have actually selected something, the following code:

1. copies the current selection text to the end of the document

2. deletes the current selection

The cursor is positioned at the Selection (as it always is).

Deleting the Selection is actually deleting the Selection range. This automatically collapses the Selection to a point, which will be the start of where the Selection was. In other words, the cursor will be at the start of the Selection, with whatever text WAS selected now moved to the end of the document.

The cursor will stay where it was (or, rather it will be at the START of what was selected).
Code:
ActiveDocument.Range.InsertAfter Selection.Text
Selection.Delete
If this does not work the way you wish, then most likely it will be an issue of not fully selecting. Whether the paragraph mark is included (or not), and whether there is an appropriate paragraph mark at the end of the document (or not) will change how it works.

Those are simple to fix.

You could make a temporary bookmark to return to the current location as Skip suggests, but it is not really needed.

Gerry
 
Gerry,

That is exactly what I was looking for and works perfectly.

Thanks a bunch!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top