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 / August 2006

Tip: Looking for answers? Try searching our database.

Hyerlink Modification help needed

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Frank - 03 Aug 2006 19:54 GMT
Hello

I have a several hundres pages with content in the following format:
<text as hyperlink><1 empty space><any text any size>

I want to have it converted to somehting like the following:
<Text from oringal hyperlink astext>
<hyperlink as URL from original hyperlink>
<any text any size>

Can someone please help on this?

Thanks for any feedback,
Frank
Dave Lett - 03 Aug 2006 21:00 GMT
Hi Frank,
This seems to do the trick on my machine.

Dim lLink As Long
Dim oLink As Hyperlink
Dim oRng As Range
For lLink = ActiveDocument.Hyperlinks.Count To 1 Step -1
   Set oLink = ActiveDocument.Hyperlinks(lLink)
   Set oRng = oLink.Range
   oRng.End = oRng.End + 1
   oRng.Characters.Last.Delete
   oRng.InsertAfter vbCrLf
   oRng.InsertBefore Text:=oLink.TextToDisplay & vbCrLf
   oLink.TextToDisplay = oLink.Address
Next lLink

HTH,
Dave

> Hello
>
[quoted text clipped - 10 lines]
> Thanks for any feedback,
> Frank
Frank - 03 Aug 2006 21:12 GMT
Awesome!
So many thanks!!!

One thing: Is it possible to strip any applid style to this "range of text"
AND set the "headline" to the Headline 2 style?

Sameple:
<Text from oringal hyperlink as Heading 2>
<hyperlink as URL as URL style>
<some text based on normal style>

Can that be done as well?
Where can I read more on how to make my own makros and fancy stuff like this
here?
Dave Lett - 04 Aug 2006 14:19 GMT
Hi Frank,

Yes, it is possible. Here's what works on my machine:

Dim lLink As Long
Dim oLink As Hyperlink
Dim oRng As Range
Dim oRngPara As Range
Dim lPara As Long
For lLink = ActiveDocument.Hyperlinks.Count To 1 Step -1
   Set oLink = ActiveDocument.Hyperlinks(lLink)
   Set oRng = oLink.Range
   oRng.End = oRng.End + 1
   oRng.Characters.Last.Delete
   oRng.InsertAfter vbCrLf
   oRng.InsertBefore Text:=oLink.TextToDisplay & vbCrLf
   oLink.TextToDisplay = oLink.Address
   '''format the paragraphs before and after
   '''1. set a range from beginning of doc
   '''to end of hyperlink para
   Set oRngPara = ActiveDocument.Range _
       (Start:=ActiveDocument.Range.Start, _
       End:=oRng.End)
   '''count the # of paras in that range
   lPara = oRngPara.Paragraphs.Count
   '''format the para before hyperlink para
   ActiveDocument.Paragraphs(lPara - 1).Range.Style = "Headline 2"
   '''format the para after hyperlink para
   ActiveDocument.Paragraphs(lPara + 1).Range.Style = "Normal"
Next lLink

You can learn a lot about macros by recording them (this is best when you
don't know what object, property, or method you need to access). I learned
this way and found it effective initially, especially considering that Word
has the largest object model of the office applications. Once I moved beyond
recording macros, I liked the book Word Programming; it's a little technical
(what should I have expected?), but it helped me understand the object
model. After that, I most often refer to the Word MVP site at
http://word.mvps.org/FAQs/General/index.htm

From there, you can find other Web sites that are very useful (I don't use
them very often, but a beginner/learner could get some excellent information
from them). Click the About Us link in the top navigation bar. If you then
"read up" on the MVPs, you will notice that many of them have their own Web
sites. Go to those Web sites and browse around. You will pick up a lot of
information.

Finally, lurk. Read posts that interest you from the usual suspects (those
who answer a lot of the questions); there excellent information. For
example, I learned that we need to enumerate through the hyperlinks
collection by starting with the last one if you intend to remove the
hyperlink from the text. That is, you can't enumerate through ALL of Word's
collections in some circumstances, but going through them in reverse order
(starting with the last) is probably the safest bet for all collections.

HTH,
Dave

> Awesome!
> So many thanks!!!
[quoted text clipped - 12 lines]
> this
> here?
 
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.