Skip to content

Instantly share code, notes, and snippets.

@huynhbaoan
Created October 27, 2025 10:02
Show Gist options
  • Select an option

  • Save huynhbaoan/1f8d4c32aaf778a3b8c61c7738cb1b8b to your computer and use it in GitHub Desktop.

Select an option

Save huynhbaoan/1f8d4c32aaf778a3b8c61c7738cb1b8b to your computer and use it in GitHub Desktop.
Vb extract url
' Returns every hyperlink in the cell (Address or SubAddress), newline-separated.
Function GetAllURLs(cell As Range) As String
Dim h As Hyperlink, out As String, one As String
If cell Is Nothing Then Exit Function
' Case 1: Rich text hyperlinks (pasted from web, like ServiceNow)
If cell.Hyperlinks.Count > 0 Then
For Each h In cell.Hyperlinks
one = h.Address
If one = "" Then one = h.SubAddress ' internal/bookmark/mailto
If one <> "" Then out = out & one & vbLf
Next h
If Len(out) > 0 Then out = Left$(out, Len(out) - 1) ' drop last LF
GetAllURLs = out
Exit Function
End If
' Case 2: HYPERLINK() formula
If cell.HasFormula Then
Dim f As String: f = cell.Formula
Dim q1 As Long, q2 As Long
q1 = InStr(1, f, """")
If q1 > 0 Then
q2 = InStr(q1 + 1, f, """")
If q2 > q1 Then
GetAllURLs = Mid$(f, q1 + 1, q2 - q1 - 1)
Exit Function
End If
End If
End If
' No link found -> return empty string (avoid 0)
GetAllURLs = ""
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment