Oh, yeah, Jonathan's code is better than the code I showed you, for
reasons Jonathan explained in a post on 10/21:
---- Original Message ----
From: "Jonathan West" <
[email protected]>
Newsgroups: microsoft.public.word.vba.general
Sent: Tuesday, October 21, 2003 5:26 p.m.
Subject: Re: Removing all hyperlinks from word doc
For ... each is a general solution to this problem, because it's guaranteed
to iterate every member of the collection, even if the loop itself adds or
removes members:
Dim pHyperlink as Word.Hyperlink
For each pHyperlink in ActiveDocument.Hyperlinks
pHyperlink.delete
Next
Hi Jezebel,
I suggest you try running that code. You will find that it does in fact
only
delete half the links.
Your first answer was better, but there's no need to check the balue of
ActiveDocument.Hyperlinks.Count every time you go round the loop.
Therefore,
your first answer can be speeded up a bit by this means
Dim x As Long
With ActiveDocument.Hyperlinks
For x = 1 to ActiveDocument.Hyperlinks.Count
.Item(1).Delete
Next x
End With
With a small number of hyperlinks, this perhaps doesn't make a
significant
difference, but if you are deleting thousands of links, avoiding that
extra
access of the object model is a noticeable speed improvement.
It might be more expected to use .Item(x).Delete instead of
..Item(1).Delete.
The latter is again a bit faster since it is often quicker to access the
first item in a collection than the last in the Word object model.