Playing with Ranges

J

JB

Hi Folks,
I'm trying to select a paragraph in my document and I may or may not
wish to insert a link into this document using Href and Anchor Styles.
In addition this link may be anywhere in the paragraph and I have to add
text to the very end of the paragraph.

I've tried to do this using ranges (I could do it using selection but I
don't want to) but have had no luck so far....

Can anyone point me in the right direction please?

Cheers

J
 
J

Jay Freedman

Hi JB,

It isn't clear what kind of trouble you're having. Please post back with the
code you're trying and describe what is or isn't happening. A small sample
of the text you're starting with and what you want to finish with would also
be helpful.

In general, once you've declared a range object (Dim myRange As Range) you
can use its .Find property to locate some piece of text. If
myRange.Find.Execute successfully finds the text, then myRange will cover
just the found text. To get the range object collapsed at the end of the
paragraph that contains that found text, use something like

Set myRange = myRange.Paragraphs(1).Range
myRange.Collapse wdCollapseEnd

To be more specific, we need the additional info.
 
E

Ed

Hi, JB. If you can select the paragraph, you should be able to set a range
to it. Then you can use InsertAfter to place your text at the end of the
paragraph. How are you getting the paragraph?

Ed
 
J

JB

Ed said:
Hi, JB. If you can select the paragraph, you should be able to set a range
to it. Then you can use InsertAfter to place your text at the end of the
paragraph. How are you getting the paragraph?

Ed
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
 

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