Extract hyperlinks from Word document (in Word)

Mindlesh

Board Regular
Joined
Apr 2, 2014
Messages
172
How can I improve this macro to:
1. list hyperlinks in order of occurrence;
2. delete blank lines;
3. allow it to be terminated with the Esc key?

Code:
Function GetAllHyperlinks()
'[URL]https://www.extendoffice.com/documents/word/1411-word-select-copy-all-hyperlinks.html#a2[/URL]
'Updateby20140214
    Dim docCurrent As Document
    Dim docNew As Document
    Dim oLink As Hyperlink
    Dim rng As Range
    Application.ScreenUpdating = False
    Set docCurrent = ActiveDocument
    Set docNew = Documents.Add
    For Each oLink In docCurrent.Hyperlinks
        Set rng = docNew.Range
        rng.Collapse
        rng.InsertParagraph
        rng.InsertAfter (oLink.Address)
    Next
    docNew.Activate
    Application.ScreenUpdating = True
    Application.ScreenRefresh
End Function
 
Last edited:

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
I suspect your code is outputting 'blanks' because it's not capturing hyperlink sub-addresses. Try:
Code:
Sub GetAllHyperlinks()
Application.ScreenUpdating = False
Dim i As Long, StrLnk As String
StrLnk = "Address" & vbTab & "Sub Address" & vbCr
With ActiveDocument
  If .Hyperlinks.Count = 0 Then Exit Sub
  For i = 1 To .Hyperlinks.Count
    With .Hyperlinks(i)
      StrLnk = StrLnk & .Address & vbTab & .SubAddress & vbCr
    End With
  Next
End With
Documents.Add
With ActiveDocument.Range
  .Text = StrLnk
  .ConvertToTable vbTab, 2
End With
Application.ScreenUpdating = True
End Sub
Note: Ordinarily, the code will execute so quickly you won't have time to press the Esc key before it terminates.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,756
Messages
6,174,320
Members
452,555
Latest member
colc007

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top