[COLOR=blue]Option Explicit[/COLOR]
[COLOR=blue]Private[/COLOR] [COLOR=blue]Function[/COLOR] GetHyperAddy(Cell [COLOR=blue]As[/COLOR] Range) [COLOR=blue]As[/COLOR] [COLOR=blue]String[/COLOR]
[COLOR=darkgreen]'Function purpose: To return a hyperlink address if one exists[/COLOR]
[COLOR=darkgreen]'Assigns a value of "None" to the string if no hyperlink is present[/COLOR]
[COLOR=blue]On Error Resume Next[/COLOR]
GetHyperAddy = Cell.Hyperlinks.Item(1).Address
[COLOR=blue]If[/COLOR] Err.Number <> 0 [COLOR=blue]Then[/COLOR] GetHyperAddy = "None"
[COLOR=blue]On Error Goto[/COLOR] 0
[COLOR=blue]End Function[/COLOR]
[COLOR=blue]Sub[/COLOR] DistillHyperlinks()
[COLOR=darkgreen]'Macro purpose: To create a list of all Hyperlinks and their[/COLOR]
[COLOR=darkgreen]'addresses contained within a selection of cells[/COLOR]
[COLOR=blue]Dim[/COLOR] HyperAddy [COLOR=blue]As[/COLOR] [COLOR=blue]String[/COLOR], cl [COLOR=blue]As[/COLOR] Range, wsTarget [COLOR=blue]As[/COLOR] Worksheet, clSource [COLOR=blue]As[/COLOR] Range
[COLOR=darkgreen]'Turn off screen flashing[/COLOR]
Application.ScreenUpdating = [COLOR=blue]False[/COLOR]
[COLOR=darkgreen]'Following required as adding worksheet changes selection[/COLOR]
[COLOR=blue]Set[/COLOR] clSource = Selection
[COLOR=darkgreen]'Check to see if a "Hyperlink List" worksheet exists, and[/COLOR]
[COLOR=darkgreen]'create it if it doesn't[/COLOR]
[COLOR=blue]On Error Resume Next[/COLOR]
[COLOR=blue]Set[/COLOR] wsTarget = Sheets("Hyperlink List")
[COLOR=blue]If[/COLOR] Err.Number <> 0 [COLOR=blue]Then[/COLOR]
[COLOR=blue]Set[/COLOR] wsTarget = Worksheets.Add
[COLOR=blue]With[/COLOR] wsTarget
.Name = "Hyperlink List"
[COLOR=blue]With[/COLOR] .Range("A1")
.Value = "Location"
.ColumnWidth = 20
.Font.Bold = [COLOR=blue]True[/COLOR]
[COLOR=blue]End With[/COLOR]
[COLOR=blue]With[/COLOR] .Range("B1")
.Value = "Displayed Text"
.ColumnWidth = 25
.Font.Bold = [COLOR=blue]True[/COLOR]
[COLOR=blue]End With[/COLOR]
[COLOR=blue]With[/COLOR] .Range("C1")
.Value = "Hyperlink Target"
.ColumnWidth = 40
.Font.Bold = [COLOR=blue]True[/COLOR]
[COLOR=blue]End With[/COLOR]
[COLOR=blue]End With[/COLOR]
[COLOR=blue]Set[/COLOR] wsTarget = Sheets("Hyperlink List")
[COLOR=blue]End[/COLOR] [COLOR=blue]If[/COLOR]
[COLOR=blue]On Error Goto[/COLOR] 0
[COLOR=darkgreen]'Loop through each cell in the user's selection and...[/COLOR]
[COLOR=blue]For Each[/COLOR] cl [COLOR=blue]In[/COLOR] clSource
[COLOR=darkgreen]'Get the hyperlink address[/COLOR]
HyperAddy = GetHyperAddy(cl)
[COLOR=blue]If[/COLOR] [COLOR=blue]Not[/COLOR] HyperAddy = "None" [COLOR=blue]Then[/COLOR]
[COLOR=darkgreen]'If Hyperlink exists, add it to the list on the target sheet[/COLOR]
[COLOR=blue]With[/COLOR] wsTarget.Range("A65536").End(xlUp).Offset(1, 0)
[COLOR=darkgreen]'Create hyperlink to cell containing hyperlink[/COLOR]
.Parent.Hyperlinks.Add Anchor:=.Offset(0, 0), _
Address:="", SubAddress:=(cl.Parent.Name) & "!" & (cl.Address)
[COLOR=darkgreen]'List text shown on hyperlink[/COLOR]
.Offset(0, 1).Value = cl.Text
[COLOR=darkgreen]'Create hyperlink to destination[/COLOR]
.Hyperlinks.Add Anchor:=.Offset(0, 2), Address:=HyperAddy
[COLOR=blue]End With[/COLOR]
[COLOR=blue]End[/COLOR] [COLOR=blue]If[/COLOR]
[COLOR=blue]Next[/COLOR] cl
wsTarget.Select
[COLOR=blue]End Sub[/COLOR]