copy paste a range of text

  • Thread starter FIRSTROUNDKO via OfficeKB.com
  • Start date
F

FIRSTROUNDKO via OfficeKB.com

Hi!

How do I copy a range text abc to xyz not in the same paragraph
to a new document


abc........
..........

.........
..........


xyz

thanks in advance
 
D

Doug Robbins - Word MVP

Use

Dim myrange As Range
Set myrange = ActiveDocument.Range
myrange.start = myrange.start + InStr(myrange, "abc") - 1
myrange.End = myrange.start + InStr(myrange, "xyz") + 2
myrange.Copy

without the -1 and the +2, what will be copied starts with the b of abc and
ends with the x of xyz. You will need to make an appropriate adjustment to
get exactly what you want.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
F

FIRSTROUNDKO via OfficeKB.com

HI

all I get is abcxyz, and not th text inbetween

Thanks

Darren
Use

Dim myrange As Range
Set myrange = ActiveDocument.Range
myrange.start = myrange.start + InStr(myrange, "abc") - 1
myrange.End = myrange.start + InStr(myrange, "xyz") + 2
myrange.Copy

without the -1 and the +2, what will be copied starts with the b of abc and
ends with the x of xyz. You will need to make an appropriate adjustment to
get exactly what you want.
[quoted text clipped - 10 lines]
thanks in advance
 
D

Doug Robbins - Word MVP

That's not what happens when I run the code.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

FIRSTROUNDKO via OfficeKB.com said:
HI

all I get is abcxyz, and not th text inbetween

Thanks

Darren
Use

Dim myrange As Range
Set myrange = ActiveDocument.Range
myrange.start = myrange.start + InStr(myrange, "abc") - 1
myrange.End = myrange.start + InStr(myrange, "xyz") + 2
myrange.Copy

without the -1 and the +2, what will be copied starts with the b of abc
and
ends with the x of xyz. You will need to make an appropriate adjustment
to
get exactly what you want.
[quoted text clipped - 10 lines]
thanks in advance
 

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