Playing with ranges **REPOST**

J

JB

Old Post-----------

Hi Guys,
Sorry I wasn't clearer.

I'm selecting the text in the paragraph manually....say the paragraph
looked like this -

"My Paragraph has SELECTED TEXT and this is what I want to be a link
entering a new word HERE".

I've tried insertafter but it goes after the paragraph and onto the new
line when I use with myRng.MoveEnd...didn't try wdcollapseEnd though.

Dim myrng As Range

Set myrng = Selection.Range
myrng = myrng.Paragraphs(1).Range

myrng.MoveEnd
myrng.InsertAfter " MyText"

Cheers

J

---------------------

Forgot to mention that after the text is selected in the para the user
clicks a custom macro button, the macro Changes the selection to make
the selected text the anchor and inserts text before the anchor which is
the Href to the linked document.

So I can't select the whole para at the start as I'll lose my selection
and I can't select the whole para at the end as I'll lose my formatting
for the anchor.

Cheers

J
 
D

Dave Lett

Hi JB,

I think you're looking for something like the following:

Dim oRng As Range
Set oRng = ActiveDocument.Range _
(Start:=Selection.Paragraphs(1).Range.End - 1, _
End:=Selection.Paragraphs(1).Range.End - 1)

oRng.InsertAfter Text:="New Text"

HTH,
Dave
 
J

JB

Dave said:
Hi JB,

I think you're looking for something like the following:

Dim oRng As Range
Set oRng = ActiveDocument.Range _
(Start:=Selection.Paragraphs(1).Range.End - 1, _
End:=Selection.Paragraphs(1).Range.End - 1)

oRng.InsertAfter Text:="New Text"

HTH,
Dave
So simple when you know how..... :)

Thanks Dave.

J
 

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