VBA to list all links (external links AND hyperlinks) together with the cells containing the links

accountant606

New Member
Joined
May 25, 2024
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hello,

I need to use VBA to list all links (both external links AND hyperlinks) in a workbook and have the location of the corresponding cells that contain these links listed beside them for reference. I do have the code (see Table 1: Code at the bottom of this post) to pull the cell reference for external links from this thread here:

VBA to list all external links together with the cells containing the links

However, the VBA does not also find hyperlinks. I need it to go one more step further to also give me the location of hyperlinks as well.

Here is an example sheet where I want to extract all links (not just external links but also hyperlinks)

Book1 (version 1).xlsm
ABC
1
25
3Link to youtube
4
5
6
7
Sheet1
Cell Formulas
RangeFormula
B2B2='[Book2-External Link.xlsx]Sheet1'!$B$2


However, when I run the macro in 'Table 1: Code', I only get this output

Book1 (version 1).xlsm
ABC
1LocationReference
2[Book1 (version 1).xlsm]Sheet1'!$B$2='[Book2-External Link.xlsx]Sheet1'!$B$2
3
4
5
6
7
Sheet2


In other words, this macro is not also detecting the hyperlink to youtube in cell B3 of 'Sheet 1'. Can you help me improve this macro to also detect hyperlinks?

Your help is greatly appreciated.
Jay


Table 1: Code

Option Explicit

Sub ListLinks()

Dim Wks As Worksheet
Dim rFormulas As Range
Dim rCell As Range
Dim aLinks() As String
Dim Cnt As Long

If ActiveWorkbook Is Nothing Then Exit Sub

Cnt = 0
For Each Wks In Worksheets
On Error Resume Next
Set rFormulas = Wks.UsedRange.SpecialCells(xlCellTypeFormulas)
On Error GoTo 0
If Not rFormulas Is Nothing Then
For Each rCell In rFormulas
If InStr(1, rCell.Formula, "[") > 0 Then
Cnt = Cnt + 1
ReDim Preserve aLinks(1 To 2, 1 To Cnt)
aLinks(1, Cnt) = rCell.Address(, , , True)
aLinks(2, Cnt) = "'" & rCell.Formula
End If
Next rCell
End If
Next Wks

If Cnt > 0 Then
Worksheets.Add before:=Worksheets(1)
Range("A1").Resize(, 2).Value = Array("Location", "Reference")
Range("A2").Resize(UBound(aLinks, 2), UBound(aLinks, 1)).Value = Application.Transpose(aLinks)
Columns("A:B").AutoFit
Else
MsgBox "No links were found within the active workbook.", vbInformation
End If

End Sub
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.

Forum statistics

Threads
1,216,500
Messages
6,131,015
Members
449,615
Latest member
Nic0la

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