Please Note: This article is written for users of the following Microsoft Excel versions: 97, 2000, 2002, and 2003. If you are using a later version (Excel 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Excel, click here: Extracting URLs from Hyperlinks.

Extracting URLs from Hyperlinks

by Allen Wyatt
(last updated January 23, 2016)

11

Mezga has a series of cells that contain hyperlinks. These hyperlinks consist of words such as "click here" or "more information." In other words, each hyperlink contains display text that is different from the underlying URL that is activated when the link is clicked. Mezga would like to know if there is a way, without using a macro, to extract the underlying URL for each of these hyperlinks and place that URL into a different cell.

Without using macros, you can do this:

  1. Right-click a hyperlink. You'll see a Context menu appear.
  2. From the Context menu, choose Edit Hyperlink. Excel displays the Edit Hyperlink dialog box. (See Figure 1.)
  3. Figure 1. The Edit Hyperlink dialog box.

  4. Select and copy (Ctrl+C) the entire URL from the Address field of the dialog box.
  5. Press Esc to close the Edit Hyperlink dialog box.
  6. Paste the URL into any cell desired.

Note that this is for a single hyperlink. If you have a whole bunch of hyperlinks in a worksheet and you want to recover the URLs, you need to do this for each and every hyperlink. Obviously this can get tedious very quickly.

The cure for tedium—like them or not—is a macro. With a macro, getting at the underlying URL for a hyperlink is child's play. All the macro needs to do is pay attention to the Address property of the hyperlink. The following is an example of a macro that will find each hyperlink in a worksheet, extract each one's URL, and stick that URL in the cell directly to the right of the hyperlink.

Sub ExtractHL()
    Dim HL As Hyperlink
    For Each HL In ActiveSheet.Hyperlinks
        HL.Range.Offset(0, 1).Value = HL.Address
    Next
End Sub

Instead of a "brute force" macro, you could also create a user-defined function that would extract and return the URL for any hyperlink at which it was pointed:

Function GetURL(rng As Range) As String
    On Error Resume Next
    GetURL = rng.Hyperlinks(1).Address
End Function

In this case you can place it where you want. If you want, for example, the URL from a hyperlink in A1 to be listed in cell C25, then in cell C25 you would enter the following formula:

=GetURL(A1)

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (3281) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) here: Extracting URLs from Hyperlinks.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He  is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Deleting a Macro

Macros are often created to accomplish a specific task, after which they are no longer needed. If you need to delete a macro ...

Discover More

Automatically Selecting Words

When editing a document, Word normally selects entire words as you use the mouse to select text. This tip explains why this ...

Discover More

Limiting Precision

There may be times you need to limit the amount of precision Excel uses in its calculations. Here is one way to accomplish ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!

More ExcelTips (menu)

References to Hyperlinks aren't Hyperlinks

Make a reference to a hyperlink in a formula, and you may be surprised that the reference doesn't return an active hyperlink. ...

Discover More

Specifying Your Target Monitor

When you create a worksheet that is destined for viewing on the Web, you will want to specify the monitor resolution you ...

Discover More

Setting Web Fonts

Is your worksheet information destined for a Web page? Here's how you can specify the fonts that should be used when Excel ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is four less than 6?

2017-02-04 15:01:48

Mostafa Ibrahim

Thanks a lot for this tip, helped me so much, and saved a lot of time.


2016-12-19 22:01:33

Ying

Hi I would like to copy a URL website link from one cell to another. When this one cell that contains the website link is updated, I would like for all the other cells to have updated URL website links too. How can I do this?

Thanks


2016-10-10 12:59:40

LH

Thank you so much for this post. You have saved me a bunch of time. ExtractHL macro worked perfectly for me.


2016-10-03 13:20:11

Kathleen

Many thanks! A colleague painstakingly put over 100 hyperlinks in cells with shorter captions, not realizing I would have to pull them all out again to copy them out to other documents. Ran Sub ExtractHL once. Boom! Great tip.


2016-08-05 00:19:25

Thankful

Function GetURL(rng As Range) As String
On Error Resume Next
GetURL = rng.Hyperlinks(1).Address
End Function

This worked like MAGIC! thanks for being awesome!


2016-06-18 05:58:07

Willy Vanhaelen

@Rob Cooper

HL.Address truncates everything after and incuding # (hash sign). I do not see a solution to this.


2016-06-14 15:08:46

Rob Cooper

Hi,
I tried the GetUrl function, but ran into the following difficulty.
The address of the hyperlink on which I applied GetUrl is:

http://documentation.custhelp.com/euf/assets/devdocs/may2016/PolicyAutomation/en/Default.htm#Guides/Policy_Modeling_User_Guide/Walkthrough_OPM.htm

i.e. it is a particular topic in an on-line book.

GetUrl only returned
http://documentation.custhelp.com/euf/assets/devdocs/may2016/PolicyAutomation/en/Default.htm,
the address only up to the first 'htm'.

Any ideas for how to return the whole address?

Thanks.


2016-05-27 13:42:09

Rob

Thanks, you rock!


2016-05-02 13:51:45

Leonardo

Nice tip, simple and very effective.

Leonardo


2016-03-13 06:54:06

Willy Vanhaelen

FORMULATEXT is introduced in Excel 2013.
These tips apply to Excel 97 ... 2003.


2016-03-12 10:32:46

Spriteup

Or without Macro fuction just:
=MID(FORMULATEXT(B1);FIND(CHAR(34);FORMULATEXT(B1))+1;FIND(CHAR(34);FORMULATEXT(B1);FIND(CHAR(34);FORMULATEXT(B1))+1)-1-FIND(CHAR(34);FORMULATEXT(B1)))

where B1 is HYPERLINK.


This Site

Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.