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 2007

Tip: Looking for answers? Try searching our database.

Removing ALL hyperlinks

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bugsy - 03 Aug 2007 17:59 GMT
I have copied a document from the internet into a WORD document (WORD 2002).
The copied document has hundreds of "hyperlinks" and "Permalinks" in it.

How can I remove ALL the links at one time (from the entire copied
document)?  It would take forever to eliminate each one separately, I think.

I am using Windows XP Home edition.

Thanks for any suggestions.
Jonathan West - 03 Aug 2007 18:08 GMT
>I have copied a document from the internet into a WORD document (WORD
>2002). The copied document has hundreds of "hyperlinks" and "Permalinks" in
[quoted text clipped - 7 lines]
>
> Thanks for any suggestions.

Dim n As Long
For n = 1 to ActiveDocument.Range.Hyperlinks.Count
 Activedocument.Range.Hyperlinks(1).Delete
Next n

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup

Edward Thrashcort - 03 Aug 2007 19:09 GMT
> Dim n As Long
> For n = 1 to ActiveDocument.Range.Hyperlinks.Count
>   Activedocument.Range.Hyperlinks(1).Delete
> Next n

Should that be

For n = ActiveDocument.Range.Hyperlinks.Count Step -1
  Activedocument.Range.Hyperlinks(n).Delete
Next n

Eddie

> *From:* "Jonathan West" <jwest@mvps.org>
> *Date:* Fri, 3 Aug 2007 18:08:39 +0100
[quoted text clipped - 15 lines]
>   Activedocument.Range.Hyperlinks(1).Delete
> Next n
Doug Robbins - Word MVP - 03 Aug 2007 22:09 GMT
No, it will work.

The following however

Dim n As Long
For n = 1 to ActiveDocument.Range.Hyperlinks.Count
 Activedocument.Range.Hyperlinks(n).Delete
Next n

would delete the first, then what was originally the third and then what was
originally the seventh, etc until it errors out because n becomes greater
than the number of paragraphs remaining in the document.

That said however, I usually start from the .Count and step backwards
through the collection when deleting items.

Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

>> Dim n As Long
>> For n = 1 to ActiveDocument.Range.Hyperlinks.Count
[quoted text clipped - 28 lines]
>>   Activedocument.Range.Hyperlinks(1).Delete
>> Next n
Edward Thrashcort - 04 Aug 2007 10:19 GMT
Doing it your way it seems that you have to wait for the collection to
"shuffle down" before removing the next link.

> For n = ActiveDocument.Range.Hyperlinks.Count Step -1

Should have been

For n = ActiveDocument.Range.Hyperlinks.Count ...TO 1... Step -1

Eddie

> *From:* "Doug Robbins - Word MVP" <dkr@REMOVECAPSmvps.org>
> *Date:* Sat, 4 Aug 2007 07:09:18 +1000
[quoted text clipped - 48 lines]
> >>   Activedocument.Range.Hyperlinks(1).Delete
> >> Next n
Jonathan West - 04 Aug 2007 13:57 GMT
>> Dim n As Long
>> For n = 1 to ActiveDocument.Range.Hyperlinks.Count
[quoted text clipped - 6 lines]
>   Activedocument.Range.Hyperlinks(n).Delete
> Next n

Try it the various different ways. They both work, but my way is marginally
the faster. The reason is that while the collection of hyperlinks is
presented as a collection, its underlying implementation is not a linked
list, and it therefore takes more time to get at the last hyperlink in the
set than the first.

Each time you remove the first hyperlink, the next one becomes the first,
and therefore the easiest to get at. You repeat that process as many times
as there were hyperlinks at the start.

Believe me, I have studied and tested this quite extensively. The code looks
a bit counterintuitive, but once you understand the underlying issues, it
does become clear.

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup

Helmut Weber - 04 Aug 2007 14:47 GMT
Hi Jonathan,

>Each time you remove the first hyperlink, the next one becomes the first,
>and therefore the easiest to get at. You repeat that process as many times
>as there were hyperlinks at the start.

sure.

Of course, the question was about the active document,
where your approach works perfectly and fast.

But there is a strange case,
where deleting hyperlinks(1) doesn't work.

It is if one wants to delete all hyperlinks in the selection
and the selection starts with a hyperlink
and there is more than one hyperlink in the selection.

In that case, the selection collapses immediately
after deleting the first hyperlink to it's start,
the start of the selection,
and then there is no more hyperlink in the selection to be found.

This is in no way meant as criticism.
It is just a marginal footnote,
a case, where Christian Freßdorf, German MVP,
and me had to think quite a while
about what was going on.

Have a nice day.

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"

Russ - 04 Aug 2007 20:42 GMT
Great information gentlemen.

Jonathan,
How could we tell what objects work like hyperlinks and are best removed by
removing the first one?

> Hi Jonathan,
>
[quoted text clipped - 26 lines]
>
> Have a nice day.

Signature

Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID

Jonathan West - 05 Aug 2007 00:22 GMT
> Great information gentlemen.
>
> Jonathan,
> How could we tell what objects work like hyperlinks and are best removed
> by
> removing the first one?

Basically, by experiment. A rule of thumb is that if the items of a
collection cannot be indexed by a name, but only by an index number, then
the chances are that they are best removed starting at the front. But its
best to check by benchmarking.

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup

Edward Thrashcort - 07 Aug 2007 17:02 GMT
I noticed back in Word2k times that the Selection object developed a lot of
quirks.  I usually assign a Selection to a Range object before working on
it.  Seems less quirky that way.

Eddie

> *From:* Helmut Weber <nbhymsjxdgcn@mailinator.com>
> *Date:* Sat, 04 Aug 2007 15:47:07 +0200
[quoted text clipped - 29 lines]
>
> Have a nice day.
Edward Thrashcort - 07 Aug 2007 17:02 GMT
Interesting!  I'll remember that trick.

Eddie

> *From:* "Jonathan West" <jwest@mvps.org>
> *Date:* Sat, 4 Aug 2007 13:57:52 +0100
[quoted text clipped - 23 lines]
> looks a bit counterintuitive, but once you understand the underlying
> issues, it does become clear.
Bugsy - 04 Aug 2007 18:08 GMT
Hey, Guys:

All of you sound like computer geniuses to me.

Unfortunately, I am a novice.  That's why I asked for help.

Undoubtedly, in my mind, what you have suggested will work . . . but I still
don't understand how to implement your suggestions.

Could you advise me on a more elementary level?  Thanks!

>I have copied a document from the internet into a WORD document (WORD
>2002). The copied document has hundreds of "hyperlinks" and "Permalinks" in
[quoted text clipped - 7 lines]
>
> Thanks for any suggestions.
Jonathan West - 04 Aug 2007 20:31 GMT
> Hey, Guys:
>
[quoted text clipped - 6 lines]
>
> Could you advise me on a more elementary level?  Thanks!

Take a look here

What do I do with macros sent to me by other newsgroup readers to help me
out?
http://www.word.mvps.org/FAQs/MacrosVBA/CreateAMacro.htm

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup

 
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.