![]() |
|
#2
|
||||
|
||||
|
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] |
| 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 |
How to find and delete duplicate words in doc
|
cinvest | Word | 1 | 09-29-2014 08:34 PM |
Macro to Delete Duplicate Rows and Retain Unique Value
|
expert4knowledge | Excel Programming | 1 | 02-17-2014 08:02 PM |
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 |