Skip to the tool
URLExtractor
Spreadsheets

How to Extract URLs from Hyperlinks in Excel

A cell showing "Click here" stores its address somewhere you cannot reach with a formula. Three methods that work — VBA, FORMULATEXT and unzipping the file — and exactly when each one applies.

By URL Extractor EditorialPublished

The short answer: it depends on how the link was made. There are two kinds of hyperlink in Excel and they need completely different approaches.

| The cell was made by | The address lives in | Use |
| --- | --- | --- |
| Insert → Link (or pasting a link) | A hidden hyperlink record | A VBA function, or unzipping the file |
| A =HYPERLINK("…","…") formula | The formula itself | FORMULATEXT |

Work out which you have first: click the cell and look at the formula bar. If you see =HYPERLINK(...), it is the second kind. If the bar shows only the display text, it is the first.

Why no plain formula can do it

This is worth understanding, because it explains why every "just use this formula" answer either fails or is really about the other kind of link.

Save a workbook with an inserted hyperlink and unzip it — an .xlsx is a ZIP archive — and you can see exactly where Excel puts things. Here is a real file with "Click here" in A2 linking to https://example.com/real-target?id=42.

The worksheet holds the display text only:

xl/worksheets/sheet1.xml — the cell and, separately, the link record
xml
<sheetData>
  <row r="2">
    <c r="A2" t="inlineStr"><is><t>Click here</t></is></c>
  </row>
</sheetData>

<hyperlinks>
  <hyperlink ref="A2" r:id="rId1"/>
</hyperlinks>

Taken from a workbook created with openpyxl 3.1.5 and unzipped; the structure is the same for files saved by Excel.

The actual address is in a separate relationships file:

xl/worksheets/_rels/sheet1.xml.rels
xml
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
  <Relationship Id="rId1"
                Type=".../relationships/hyperlink"
                Target="https://example.com/real-target?id=42"
                TargetMode="External"/>
</Relationships>

Two files, joined by rId1. Excel's formula language has no function that can follow that join, which is why the address is genuinely unreachable from a worksheet formula.

It also explains the thing that catches people out: save the sheet as CSV and the addresses vanish. A CSV has one value per cell, and the value is "Click here".

Method 1 — a VBA function (for inserted hyperlinks)

  1. 1

    Open the VBA editor

    Press Alt + F11. In the menu, choose Insert → Module.

  2. 2

    Paste the function

    Paste the code below into the module window, then close the editor.

  3. 3

    Use it like any formula

    In a spare column, enter =GetURL(A2) and fill down. Cells with no hyperlink return an empty string rather than an error.

  4. 4

    Save as .xlsm

    A workbook containing macros must be saved as Excel Macro-Enabled Workbook (.xlsm). Saving as .xlsx silently drops the code.

VBA — paste into a module
plain
Function GetURL(cell As Range) As String
    ' Returns the address behind an inserted hyperlink, or "" if there is none.
    On Error Resume Next
    GetURL = cell.Hyperlinks(1).Address

    ' A link inserted over a range, rather than a single cell, is reachable
    ' through the parent range instead.
    If GetURL = "" Then
        GetURL = cell.Parent.Hyperlinks(1).Address
    End If
End Function

Uses the documented Range.Hyperlinks and Hyperlink.Address members of the Excel object model. Requires Excel for Windows or Mac; VBA is not available in Excel for the web.

Method 2 — FORMULATEXT (for HYPERLINK formulas)

  1. 1

    Check the formula bar

    This only applies when the cell actually contains =HYPERLINK("https://…","Label"). If the formula bar shows plain text, use method 1 or 3.

  2. 2

    Pull out the formula as text

    =FORMULATEXT(A3) returns the whole formula as a string, quotes and all.

  3. 3

    Take the first quoted argument

    Everything between the first pair of double quotes is the address.

Excel — extract the address from a HYPERLINK formula
formula
=IFERROR(
   MID(
     FORMULATEXT(A3),
     FIND("""", FORMULATEXT(A3)) + 1,
     FIND("""", FORMULATEXT(A3), FIND("""", FORMULATEXT(A3)) + 1)
       - FIND("""", FORMULATEXT(A3)) - 1
   ),
   ""
 )

FORMULATEXT was introduced in Excel 2013 and returns #N/A for a cell that contains no formula, which the IFERROR handles. Doubled quotes are how a literal " is written inside an Excel string.

Method 3 — read the file directly (best for bulk, no macros)

If you have hundreds of links, or a workbook you would rather not enable macros in, go to the file itself. This needs no Excel at all.

  1. Take a copy of the workbook and rename report.xlsx to report.zip.
  2. Extract it.
  3. Open xl/worksheets/_rels/sheet1.xml.rels in a text editor. Every Target="…" with TargetMode="External" is a link address.
  4. Select the contents of that file, copy it, and paste it into the text extractor — it pulls out every address and ignores the XML around them.

That gets you all the addresses quickly. What it does not give you is the cell each one belongs to — for that you need to match r:id values between sheet1.xml and the .rels file, which is a job for a script rather than a text editor. For most tasks ("give me every link in this workbook") the list is what you actually wanted.

Frequently asked questions

Why does pasting my spreadsheet into a text extractor only give me the labels?

Because the clipboard carries the displayed values. The address is stored in a separate record that copying as plain text does not include — this is the same reason saving as CSV loses the links.

Is there a native Excel function for this yet?

There is no worksheet function that returns the target of an inserted hyperlink. FORMULATEXT covers HYPERLINK formulas only. The three methods above are the practical routes.

Can I do this in Excel for the web?

VBA is not available there. Either open the workbook in desktop Excel, or use the unzip method, which needs no Excel at all. Office Scripts can read hyperlinks in the web version if scripting is enabled for your tenant.

The function returns nothing for some cells.

Those cells probably have no hyperlink — they may just look like links because of formatting. It can also happen when one hyperlink was applied across a merged or multi-cell range; the fallback line in the function above covers that case. And remember the recalculation gotcha: press Ctrl + Alt + F9.

Sources

URL Extractor from TextPaste the .rels file here to pull out every address at once.

Tools used in this guide

Related guides

Share this pageWhatsAppXLinkedInFacebook