Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / November 2004

Tip: Looking for answers? Try searching our database.

Playing with Ranges

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
JB - 02 Nov 2004 17:02 GMT
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
Jay Freedman - 02 Nov 2004 17:29 GMT
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.

Signature

Regards,
Jay Freedman
Microsoft Word MVP          FAQ: http://word.mvps.org

> Hi Folks,
> I'm trying to select a paragraph in my document and I may or may not
[quoted text clipped - 10 lines]
>
> J
Ed - 02 Nov 2004 17:36 GMT
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 Folks,
> I'm trying to select a paragraph in my document and I may or may not
[quoted text clipped - 10 lines]
>
> J
JB - 02 Nov 2004 17:47 GMT
> 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
[quoted text clipped - 16 lines]
>>
>>J

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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.