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 / September 2005

Tip: Looking for answers? Try searching our database.

Removing hyperlinks

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
J Lenihan - 08 Sep 2005 20:43 GMT
I have a number of documents with tons of hypelinks that no longer are valid.
Is there a way to progromatically search thru the document and remove the
links? The text is ok to stay but removing the links and color would be great!

Thanks!
Greg Maxey - 08 Sep 2005 22:22 GMT
Try:

Sub ScratchMacro()
Dim oFld As Field
For Each oFld In ActiveDocument.Fields
 If oFld.Type = wdFieldHyperlink Then
   oFld.Unlink
 End If
Next

End Sub

Signature

Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

> I have a number of documents with tons of hypelinks that no longer
> are valid. Is there a way to progromatically search thru the document
> and remove the links? The text is ok to stay but removing the links
> and color would be great!
>
> Thanks!
Jonathan West - 08 Sep 2005 23:05 GMT
> Try:
>
[quoted text clipped - 7 lines]
>
> End Sub

Sorry Greg, but that only remove half the hyperlinks (try it!)

This will remove all of them

Sub ScratchMacro()
Dim iFld As Long
For iFld = ActiveDocument.Fields to 1 Step -1
 If ActiveDocument.Fields(iFld).Type = wdFieldHyperlink Then
   ActiveDocument.Fields(iFld).Unlink
 End If
Next iFld
End Sub

Better still (i.e. quicker) is to avoid bothering with all the non-hyperlink
fields, like this

Sub ScratchMacro()
Dim iFld As Long
For iFld = ActiveDocument.Hyperlinks to 1 Step -1
 ActiveDocument.Hyperlinks(1).Delete
Next iFld
End Sub

(Yes, it is repeatedly deleting the first hyperlink in the document. Think
about why that works <g>)

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org 

Greg Maxey - 09 Sep 2005 00:12 GMT
Jonathan,

I did try it and just tried it again.  It works here to unlink 1 of 1 or 10
of 10.  It unlinks all in the document.

I remember you showing the technique of working from the last to the first
using step -1 when deleting indexed items, but that doesn't appear to be
necessary in this case.  At least the code I posted is working to unlink all
hyperlinks in my test document.  I am using made up links like test@msn.com
etc.

.

Signature

Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

>> Try:
>>
[quoted text clipped - 33 lines]
> (Yes, it is repeatedly deleting the first hyperlink in the document.
> Think about why that works <g>)
Jay Freedman - 08 Sep 2005 22:36 GMT
>I have a number of documents with tons of hypelinks that no longer are valid.
>Is there a way to progromatically search thru the document and remove the
>links? The text is ok to stay but removing the links and color would be great!
>
>Thanks!

See
http://groups-beta.google.com/group/microsoft.public.word.docmanagement/msg/4fbf
763bab8a5bf5?hl=en
.

--
Regards,
Jay Freedman
Microsoft Word MVP        FAQ: http://word.mvps.org
 
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.