Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-16-2015, 08:41 AM
dabbler dabbler is offline Keep text selected after paste Windows 8 Keep text selected after paste Office 2013
Novice
Keep text selected after paste
 
Join Date: Jan 2015
Posts: 6
dabbler is on a distinguished road
Default Keep text selected after paste

I've tried to search for a similar thread but I wasn't able to find one, so:



I d like that word would maintain the text that I've just pasted selected. I mean, I open a new document, select a piece of text and paste it in this new document, but I would like to see it still selected to know where the pasted text begins.

I don't know if I made myself clear.
It's such a small thing but it creates lots of problems when I work with long texts.

Can anyone help?
Reply With Quote
  #2  
Old 01-17-2015, 12:02 AM
macropod's Avatar
macropod macropod is online now Keep text selected after paste Windows 7 64bit Keep text selected after paste Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 20,704
macropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant future
Default

Hi dabbler,

Word has no option for doing that.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 01-17-2015, 03:18 AM
dabbler dabbler is offline Keep text selected after paste Windows 8 Keep text selected after paste Office 2013
Novice
Keep text selected after paste
 
Join Date: Jan 2015
Posts: 6
dabbler is on a distinguished road
Default

Thanks,

now at least I know that there's no use to search for it.
Reply With Quote
  #4  
Old 01-19-2015, 12:16 AM
eNGiNe eNGiNe is offline Keep text selected after paste Windows 7 32bit Keep text selected after paste Office 2010 64bit
Expert
 
Join Date: Jan 2012
Location: Brussels [BE]
Posts: 743
eNGiNe is on a distinguished road
Default

Perhaps you could try applying a character style to the selection to give it a specific colour? a quick test with 2010 gives me visibly different text in the target document, while the text in the source document remains highlighted. To clear the colour, select the text you marked/pasted and press ctrl+spacebar.

YMMD :-}
Reply With Quote
  #5  
Old 01-19-2015, 08:38 AM
gmaxey gmaxey is offline Keep text selected after paste Windows 7 32bit Keep text selected after paste Office 2010 (Version 14.0)
Word MVP 2003-2009
 
Join Date: May 2010
Location: Marble, NC
Posts: 1,176
gmaxey has a spectacular aura aboutgmaxey has a spectacular aura aboutgmaxey has a spectacular aura about
Default

If you don't need special paste features you might use a simple macro:

Code:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
  Dim oRng As Word.Range
  Set oRng = Selection.Range
  oRng.Paste
  oRng.Select
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #6  
Old 07-20-2018, 07:46 AM
joelraffel joelraffel is offline Keep text selected after paste Windows XP Keep text selected after paste Office 2003
Novice
 
Join Date: Jul 2018
Posts: 1
joelraffel is on a distinguished road
Default

Quote:
Originally Posted by gmaxey View Post
If you don't need special paste features you might use a simple macro:

Code:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
  Dim oRng As Word.Range
  Set oRng = Selection.Range
  oRng.Paste
  oRng.Select
End Sub

The above works well Greg, thanks. As you say, this only works with 'normal paste'. I need the above to work with a special paste. Is this possible?

I often copy text from pdf and paste into word. I want a single macro which can:
- do a 'MergeFormatting' paste into Word, and then
- have this pasted text automatically selected, and then
- I will add more to the macro, including a way to replace unwanted paragraphs with spaces (already described by others, and I already have this code).

Any help would be MUCH appreciated!
Reply With Quote
  #7  
Old 07-31-2019, 05:34 AM
ours_paresseux ours_paresseux is offline Keep text selected after paste Windows 7 64bit Keep text selected after paste Office 2010
Novice
 
Join Date: Jul 2019
Posts: 2
ours_paresseux is on a distinguished road
Default

Quote:
Originally Posted by gmaxey View Post
If you don't need special paste features you might use a simple macro:

Code:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
  Dim oRng As Word.Range
  Set oRng = Selection.Range
  oRng.Paste
  oRng.Select
End Sub

Thank you Greg, this is very helpful and solved the same problem that I was having.
Please could you break down the code so I can understand what each part means? I am new to vba. Thanks!
Reply With Quote
  #8  
Old 07-31-2019, 06:10 AM
gmaxey gmaxey is offline Keep text selected after paste Windows 10 Keep text selected after paste Office 2016
Word MVP 2003-2009
 
Join Date: May 2010
Location: Marble, NC
Posts: 1,176
gmaxey has a spectacular aura aboutgmaxey has a spectacular aura aboutgmaxey has a spectacular aura about
Default

OP,


I'm not a computer scientists, but something like this:

Code:
Sub ScratchMacro()
'oRng is a named variable.  I just made it up using o meaning object and Rng meaning range
'Dim declares a named variable and defines the data type in the Word object model.  In this case
'a Word.Range
Dim oRng As Word.Range
  'Use Set to set the range object to a range in the document e.g., the Selection.Range
  Set oRng = Selection.Range
  'Paste is a method of a range object and puts the contents in and expands the range.
  oRng.Paste
  'Select is a method of a range object and selects the defined range.
  oRng.Select
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #9  
Old 08-01-2019, 12:29 AM
ours_paresseux ours_paresseux is offline Keep text selected after paste Windows 7 64bit Keep text selected after paste Office 2010
Novice
 
Join Date: Jul 2019
Posts: 2
ours_paresseux is on a distinguished road
Default

Thanks Greg for your quick reply.
What I was wondering was at what point does the code say to select what had just been pasted. Now I understand much better
Reply With Quote
  #10  
Old 01-08-2021, 01:56 AM
davidswb davidswb is offline Keep text selected after paste Windows 10 Keep text selected after paste Office 2019
Novice
 
Join Date: Jan 2021
Posts: 2
davidswb is on a distinguished road
Default

Quote:
Originally Posted by gmaxey View Post
If you don't need special paste features you might use a simple macro:

Code:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
  Dim oRng As Word.Range
  Set oRng = Selection.Range
  oRng.Paste
  oRng.Select
End Sub
Hi Greg,
For the macro belwo you once posted is there a way to do the same thing using PasteSpecial (unformated text) with the Select at the end? I've been trying and have not any success.

Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim oRng As Word.Range
Set oRng = Selection.Range
oRng.Paste
oRng.Select
End Sub

Many thanks
David
Reply With Quote
  #11  
Old 01-08-2021, 09:09 AM
gmaxey gmaxey is offline Keep text selected after paste Windows 10 Keep text selected after paste Office 2016
Word MVP 2003-2009
 
Join Date: May 2010
Location: Marble, NC
Posts: 1,176
gmaxey has a spectacular aura aboutgmaxey has a spectacular aura aboutgmaxey has a spectacular aura about
Default

Interesting. It doesn't behave the same. Someone may have a better idea and I am short on time but this might work:

Code:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim oRng As Word.Range
Dim lngS As Long, lngE As Long
  Set oRng = Selection.Range
  lngS = Len(oRng.Paragraphs(1).Range.Text)
  oRng.PasteSpecial DataType:=wdPasteText
  lngE = Len(oRng.Paragraphs(1).Range.Text)
  oRng.MoveStart wdCharacter, -(lngE - lngS)
  oRng.Select
lbl_Exit:
  Exit Sub
End Sub
Reply With Quote
  #12  
Old 01-08-2021, 10:06 AM
davidswb davidswb is offline Keep text selected after paste Windows 10 Keep text selected after paste Office 2019
Novice
 
Join Date: Jan 2021
Posts: 2
davidswb is on a distinguished road
Default

Hi Greg,

Many thanks.

I tried the revised macro, but it only selects the last line.
Is there an adjustment that can be made to select all the text pasted?

Best regards,
David
Reply With Quote
  #13  
Old 01-08-2021, 10:38 AM
gmaxey gmaxey is offline Keep text selected after paste Windows 10 Keep text selected after paste Office 2016
Word MVP 2003-2009
 
Join Date: May 2010
Location: Marble, NC
Posts: 1,176
gmaxey has a spectacular aura aboutgmaxey has a spectacular aura aboutgmaxey has a spectacular aura about
Default

Davd,

I just don't see a simple solution. This may work, but in complex documents with things other than text, it might fall over:

Code:
Sub ScratchMacro()
  'A basic Word macro coded by Greg Maxey
  Dim oRng As Word.Range
  Dim lngS As Long, lngE As Long
     Set oRng = Selection.Range
     lngS = Len(ActiveDocument.Range.Text)
     oRng.PasteSpecial DataType:=wdPasteText
     lngE = Len(ActiveDocument.Range.Text)
     oRng.MoveStart wdCharacter, -(lngE - lngS)
     oRng.Select
  lbl_Exit:
     Exit Sub
  End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #14  
Old 01-10-2021, 06:53 PM
Guessed's Avatar
Guessed Guessed is offline Keep text selected after paste Windows 10 Keep text selected after paste Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 2,024
Guessed is a name known to allGuessed is a name known to allGuessed is a name known to allGuessed is a name known to allGuessed is a name known to allGuessed is a name known to all
Default

Using the same principle, this appears to work but is a bit simpler than Greg's code.
Code:
Sub ScratchMacro()
Dim oRng As Word.Range, lngS As Long
  Set oRng = Selection.Range
  lngS = oRng.Start
  oRng.PasteSpecial DataType:=wdPasteText
  oRng.Start = lngS
  oRng.Select
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #15  
Old 01-11-2021, 09:54 AM
gmaxey gmaxey is offline Keep text selected after paste Windows 10 Keep text selected after paste Office 2016
Word MVP 2003-2009
 
Join Date: May 2010
Location: Marble, NC
Posts: 1,176
gmaxey has a spectacular aura aboutgmaxey has a spectacular aura aboutgmaxey has a spectacular aura about
Default

Andrew,


Of course! Always helps when some like you looks at the problem with a fresh set of eyes. Makes one rethink:


Code:
Sub ScratchMacroII()
Dim oRng As Word.Range
   Set oRng = Selection.Range.Duplicate
   Selection.PasteSpecial DataType:=wdPasteText
   Selection.Start = oRng.Start
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
Reply

Tags
copy and paste, text selection

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to find text in between two characters and then format selected text? qcom Word 5 02-19-2015 11:23 PM
Keep text selected after paste Getting mult resps. selected in listbox to concatenate & paste at a bookmark in Word marksm33 Word VBA 3 01-15-2015 05:59 PM
Keep text selected after paste Formatting affecting more than selected text esteban Word 7 05-25-2012 04:34 AM
Keep text selected after paste Do NOT print selected text Tracy Word 2 09-11-2011 07:25 AM
Selected text and logo in one macro marijke Word VBA 0 08-24-2009 07:01 AM

Other Forums: Access Forums - Senior Forums

All times are GMT -7. The time now is 08:57 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2021 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft