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 sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remove all Hyperlinks in Word Doc 4

Status
Not open for further replies.

DbHd

Programmer
Dec 20, 2004
39
I copy/paste stock reports (for my own use) from web sites to Word. They are loaded with hyperlinks I don't want to keep (I want the text, not the links).

I select the entire doc and set the style to normal but that doesn't do it. If I select the entire doc, "Remove Hyperlinks" is greyed out.

Does anybody have a method for this?
 
One way is, go to Format tab and select Styles and Formatting. The Styles and Formatting window will show on the right side, under "Pick formatting to apply" select something for example HTML Variable. That will remove the hyperlinks, then scroll down and select Normal. That should work.

Tim
 
Are you saying that one should set the entire document to hyperlink format, remove the hyperlinks and then change back?

[yinyang] Madawc Williams (East Anglia, UK) [yinyang]
 
How about using the Edit..Paste Special..Unformatted Text option?
 
Code:
Sub RemoveHyperlinks()
Dim myHype As Hyperlink
Do Until ActiveDocument.Hyperlinks.Count = 0
    For Each myHype In ActiveDocument.Hyperlinks
        myHype.Delete
    Next
Loop
End Sub

This may, or may not, work for all versions. It works for Word XP (2002). Note the loop.


You would think simply stating each one should be deleted would work - such as:
Code:
For Each myHype In ActiveDocument.Hyperlinks
    myHype.Delete
Next
It does not. It - for some strange reason - sometimes deletes HALF of them. If you put a watch on the hyperlink count you can see it halves, then halves again. At least some time. I am not sure why. You would think the hyperlink is a normal type object, but there is SOME property that seems to persist for a while. Therefore the loop until the count is actually = 0.

Gerry
 
Thanks,

Your second example is what happened to me. I'll try your first one tonight.
 
Thanks fumei,

I tried it and it works like a charm. In this age of the internet that sould be a built-in function. I'll put it on each of my PC's!
 
Gentlemen,

Deletions should always be done 'bottom up'.

The problem with running through a collection and deleting as you go is that the collection (and your position in it) changes on each iteration. I do accept that in a case like this it is (a) not exactly obvious and (b) rather poor design, but the way to make sure you delete them all is:

Code:
[blue]For h = ActiveDocument.Hyperlinks.Count To 1 Step -1
  ActiveDocument.Hyperlinks(h).Delete
Next[/blue]

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
Tony is, as usual, correct. Bottoms UP! Cheers.

Gerry
 
Simply:
On the Edit menu, click Select All.
Press CTRL+SHIFT+F9 on your keyboard.
 
Hi bechmann,

I seem to remember this coming up before but can't find it at the moment. CTRL+SHIFT+F9 unlinks ALL FIELDS, not just hyperlinks, so if you have no other linked fields within the document it will work but should be used with caution if undesired side-effects are to be avoided.

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
Bit late now, but regarding deletion of collection items: The solution I usually use, which avoids the need to declare a variable, is:
Code:
Do
ActiveDocument.Hyperlinks(1).delete
loop until activedocument.hyperlinks.count = 0
It works because when you delete the top item in the collection, the remaining members all shuffle up one position, like sweets out of a Pez dispenser.
This is also why Fumei had the problem with only half the hyperlinks being deleted - you delete hyperlink 1, hyperlink 2 moves into position no. 1, then you go to the "next" member, which is now hyperlink 3 !

Andy.

-------
I am not responsible for any "Sponsored Links" which may appear in my messages.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top