Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Strip URL from TextLink encoded Hyperlink in Word 2003/2007

Status
Not open for further replies.

frankki

Technical User
Jul 4, 2006
10
EU
Hi Champs

I have a URL displayed as textlink = URL not visible = encoded as Hyperlink

Is there a way to strip the underlaying URL from that textlink to display the URL encoded as hyperlink instead of the textlink.

Sure, by using VBA...
 
Your term use is a bit incorrect.

If I understand you, you want to change the text displayed for a hyperlink, to the actual address of the hyperlink.

Easy.
Code:
Selection.Hyperlinks(1).TextToDisplay = Selection.Hyperlinks(1).Address
Put the cursor in the hyperlink displayed text, run the code.

The text displayed will become the address.

Eg.

BEFORE
Text displayed: "Mapquest"
Links to: "
AFTER
Text displayed: "Links to: "
Textlink / Hyperlink...there is no difference. You do not "strip" anything. You do not change a textlink to a hyperlink. The text displayed for a hyperlink is...the text displayed. There is no "instead of".

If you want to change ALL your hyperlinks to the address.
Code:
Sub ChangeHyperlinks()
Dim oHyperlink As Hyperlink
For Each oHyperlink In ActiveDocument.Hyperlinks
  oHyperlink.TextToDisplay = oHyperlink.Address
Next
End Sub
Done.

Gerry
My paintings and sculpture
 
Awesome!
Thanks so much!

However, I am facing one issue, thought nit would be easier once I have the code....

Is it possible to maintain the Text of the Link as text, and put the underlaying hyperling as URL below that one?

Before = CLickable Textlink (URL not visible)
After = Text as txt
URL as url

???
 
Thanks again for this one!
It really works incredebly fast!

Do you also know a method to delete the last two coloumns of the table prior removing the table and converting the containing text as per your above sample?
 
Not easily. Think about it. What does "below" mean???

You will have to describe EXACTLY the layout of the text. And describe EXACTLY what it is you want to do.

Before = CLickable Textlink (URL not visible)
After = Text as txt
URL as url

Before = Mapquest (a hyperlink)

After = Mapquest (NOT a hyperlink)

So the text is now NOT a hyperlink, and a new hyperlink is created "below" it? In a new paragraph? How are you going to make it "below"?

It is possible, but what is the business case for this? It would take a bit of fussing, which I am not going to do.

Gerry
My paintings and sculpture
 
hm, sorry, didnt meant to bother you with this.

Thought it is easy by "duplicating" the Hyperlink, adding a paragraph mark before it to have it in the new row, and then searching for something two hyperlinks in a row , where the first one is being replaced by its TextToDisplay value.

I just did found no way to "duplicate" a hyperlink..

However, thanks for your hints and advises!
That really brought me forward a bit :)
 
It is not a bother. It is simply you are not giving full information. We do not read minds.
Thought it is easy by "duplicating" the Hyperlink, adding a paragraph mark before it to have it in the new row, and then searching for something two hyperlinks in a row , where the first one is being replaced by its TextToDisplay value.
Row? You never mentioned a row.

So this is in a table? Do you not think that is relevant?

Does this mean you want to make a new row? Or by new row do you mean NOT in a table, but a new line, separated by a paragraph mark?

My point is that you must describe things precisely. We can not read minds, nor can we see what is on your screen.

What do you mean by searching for two hyperlinks in a row? Do you mean NEXT? That is, hyperlink, then the NEXT hyperlink? Do you really mean searching for two hyperlinks in a table row?

Interpreting what you are posting - but not totally sure it is correct, it seems like what you are asking is:

1. select a hyperlink
2. pick up the Address
3. remove the hyperlink (but leave the displayed text)
4. add a paragraph mark
5. insert a new hyperlink using the Address picked up, and having the displayed text the same Address

This does that, when the Selection is IN a hyperlink.

Code:
Sub ChangeLinkCrap()
Dim strAddress As String
strAddress = Selection.Hyperlinks(1).Address
With Selection
   .Hyperlinks(1).Delete
   .EndKey Unit:=wdLine
   .TypeParagraph
End With
   ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, _
   Address:=strAddress, SubAddress:="", _
   ScreenTip:="", TextToDisplay:=strAddress
End Sub[/vba]

Have you tried using the macro recorder?  It is true the macro recorder would not work correctly, but it would give you a good idea of what to do.

The reason the macro recorder would not work is that recording does not allow the use of variables.  So the values of the Address and TextToDisplay are recorded literally.

Gerry
[url=http://www3.telus.net/public/fumei/]My paintings and sculpture[/url]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top