Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 12-30-2016, 04:56 PM
macropod's Avatar
macropod macropod is offline Use Word VBA to find, delete and insert duplicate hyperlinks Windows 7 64bit Use Word VBA to find, delete and insert duplicate hyperlinks Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,513
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Try the following macro.

Notes:
1. None of the hyperlinks in your document are in paragraphs using the Heading 1 Style - they use a variety of other styles.
2. Some paragraphs have multiple hyperlinks, so only the first one is processed.
3. As coded, the macro adds the new hyperlink to the first word in the paragraph (i.e. the word after the paragraph's #).
Code:
Sub Demo()
Application.ScreenUpdating = False
Dim RngDoc As Range, RngLnk As Range, HLnk As Hyperlink, StrAddr
With ActiveDocument
  Set RngDoc = .Range: Set RngLnk = .Range(0, 0)
  If .TablesOfContents.Count > 0 Then
    RngDoc.Start = .TablesOfContents(.TablesOfContents.Count).Range.End
  End If
End With
For Each HLnk In RngDoc.Hyperlinks
  If HLnk.Range.Paragraphs(1).Range <> RngLnk Then
    Set RngLnk = HLnk.Range.Paragraphs(1).Range
    With RngLnk
      StrAddr = .Hyperlinks(1).Address
      HLnk.Range.Fields(1).Unlink
      .Hyperlinks.Add Anchor:=.Words.First, Address:=StrAddr, TextToDisplay:=.Words.First.Text
    End With
  End If
Next
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
 

Tags
hyperlinks, search and replace, vba in microsoft word



Similar Threads
Thread Thread Starter Forum Replies Last Post
Find last word in paragraph and delete it Dave T Word VBA 3 05-21-2015 12:40 AM
Use Word VBA to find, delete and insert duplicate hyperlinks How to find and delete duplicate words in doc cinvest Word 1 09-29-2014 08:34 PM
Use Word VBA to find, delete and insert duplicate hyperlinks Macro to Delete Duplicate Rows and Retain Unique Value expert4knowledge Excel Programming 1 02-17-2014 08:02 PM
Use Word VBA to find, delete and insert duplicate hyperlinks Find all email addresses in word document and delete Chayes Word VBA 14 10-22-2013 06:30 AM
Insert Multiple hyperlinks to word repeated in doc - easily synses Word 8 02-24-2012 05:17 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:57 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft