Paste Special Macro -- how to place cursor at end of paste?

  • Thread starter todd m via OfficeKB.com
  • Start date
T

todd m via OfficeKB.com

In my paste special macro, I wish that the cursor would appear at the end of
the paste rather than at the beginning. The "placement" variant in the
PasteSpecial method doesn't seem to do the trick. So, for now, I'm inserting
dummy text ("&&") as a work around. I suspect there is a much better way
than what I'm doing. Any thoughts? Here's my work-around.

Sub paste_special()
'
' paste_special Macro
' Macro recorded 7/27/2005 by Todd E. Marlette
'
' INSERT DUMMY TEXT ("&&")
Selection.TypeText Text:="&&"
Selection.MoveLeft Unit:=wdCharacter, Count:=2

' PASTE SPECIAL
Selection.Range.PasteSpecial DataType:=wdPasteText

' SEARCH FOR DUMMY TEXT AND THEN DELETE
' TO PLACE CURSOR AT END OF PASTED TEXT
Selection.Find.ClearFormatting
With Selection.Find
.Text = "&&"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.MoveLeft Unit:=wdCharacter, Count:=1

End Sub
 
K

Klaus Linke

Hi Todd,

If you use
Selection.PasteSpecial DataType:=wdPasteText
the selection will end up at the end of the pasted text.

I hadn't known about the different behaviour of
Selection.Range.PasteSpecial DataType:=wdPasteText
and had (up to now) remembered the original Selection.Start to jump there
after the paste, if I needed to end up there.

Nice trick ;-)

Regards,
Klaus
 
C

Chuck Henrich

Is there a reason you're using Selection.Range.PasteSpecial instead of
Selection.PasteSpecial? If not, then Selection.PasteSpecial should do what I
gather you're trying to do without the extra code - position the insertion
point at the end of the pasted text instead of the beginning.
 

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