Loading
Excel.Tips.Net ExcelTips (Menu Interface)

Extracting URLs from Hyperlinks

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.

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.

Related Tips:

Solve Real Business Problems Master business modeling and analysis techniques with Excel and transform data into bottom-line results. This hands-on, scenario-focused guide shows you how to use the latest Excel tools to integrate data from multiple tables. Check out Microsoft Excel 2013 Data Analysis and Business Modeling today!

 

Leave your own comment:

*Name:
Email:
  Notify me about new comments ONLY FOR THIS TIP
Notify me about new comments ANYWHERE ON THIS SITE
Hide my email address
*Text:
*What is 5+3 (To prevent automated submissions and spam.)
 
 
           Commenting Terms

Comments for this tip:

Thankful    05 Aug 2016, 00:19
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!
Willy Vanhaelen    18 Jun 2016, 05:58
@Rob Cooper

HL.Address truncates everything after and incuding # (hash sign). I do not see a solution to this.
Rob Cooper    14 Jun 2016, 15:08
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.
Rob    27 May 2016, 13:42
Thanks, you rock!
Leonardo    02 May 2016, 13:51
Nice tip, simple and very effective.

Leonardo
Willy Vanhaelen    13 Mar 2016, 06:54
FORMULATEXT is introduced in Excel 2013.
These tips apply to Excel 97 ... 2003.
Spriteup    12 Mar 2016, 10:32
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.
 
 

Our Company

Sharon Parq Associates, Inc.

About Tips.Net

Contact Us

 

Advertise with Us

Our Privacy Policy

Our Sites

Tips.Net

Beauty and Style

Cars

Cleaning

Cooking

DriveTips (Google Drive)

ExcelTips (Excel 97–2003)

ExcelTips (Excel 2007–2016)

Gardening

Health

Home Improvement

Money and Finances

Organizing

Pests and Bugs

Pets and Animals

WindowsTips (Microsoft Windows)

WordTips (Word 97–2003)

WordTips (Word 2007–2016)

Our Products

Helpful E-books

Newsletter Archives

 

Excel Products

Word Products

Our Authors

Author Index

Write for Tips.Net

Copyright © 2016 Sharon Parq Associates, Inc.