How to Get Hyperlink from an Excel Cell with VBA (3 Methods)

Get FREE Advanced Excel Exercises with Solutions!

In this article, I’ll show you how you can get the hyperlink from an Excel cell with VBA. You’ll learn to get the hyperlink from a single cell, as well as from a range of cells or the whole worksheet.


Get Hyperlink from an Excel Cell with VBA (Quick View)

Sub Get_Hyperlink_from_Whole_Worksheet()

Set Rng = ActiveSheet.UsedRange

Links = ""

For i = 1 To Rng.Hyperlinks.Count
    Links = Links + vbNewLine + vbNewLine + Rng.Hyperlinks(i).Address
Next i

MsgBox Links

End Sub

VBA Code to Get Hyperlink From Excel Cell


How to Get Hyperlink from an Excel Cell with VBA

Here we’ve got a worksheet that contains some hyperlinks to a range of categories.

Worksheet to Get Hyperlink from an Excel Cell with VBA

Our objective today is to get the hyperlinks from the Excel cells with VBA.


1. Get Hyperlink from a Single Cell with Excel VBA

First of all, we’ll learn to get the hyperlink from a single cell. For example, let’s try to extract the hyperlink from cell C3 of the worksheet.

The VBA code will be:

⧭ VBA Code:

Sub Get_Hyperlink_from_Single_Cell()
Cell = "C3"
Link = Range(Cell).Hyperlinks(1).Address
MsgBox Link
End Sub

VBA Code to Get Hyperlink from an Excel Cell with VBA

⧭ Output:

Run the code. It’ll display the hyperlink from cell C3 of the active worksheet.

Read More: VBA to Add Hyperlink to Cell Value in Excel


2. Get Hyperlink from a Range of Cells with Excel VBA

We’ve learned to get the hyperlink from a single cell with Excel VBA. This time we’ll get the hyperlinks from a range of cells.

For example, let’s try to get all the hyperlinks from the range B2:C6 of the active worksheet.

The VBA code will be:

⧭ VBA Code:

Sub Get_Hyperlink_from_a_Range_of_Cells()

Set Rng = Range("B2:C16")

Links = ""

For i = 1 To Rng.Hyperlinks.Count
    Links = Links + vbNewLine + vbNewLine + Rng.Hyperlinks(i).Address
Next i

MsgBox Links

End Sub

VBA Code to Get Hyperlink from an Excel Cell with VBA

⧭ Output:

Run the code. It’ll display all the hyperlinks from the range B2:C6 of the active worksheet.

Read More: Excel VBA: Add Hyperlink to Cell in Another Sheet


3. Get Hyperlink from the Whole Worksheet with Excel VBA

Finally, we’ll learn to extract hyperlinks from the whole worksheet. The VBA code will be:

⧭ VBA Code:

Sub Get_Hyperlink_from_Whole_Worksheet()

Set Rng = ActiveSheet.UsedRange

Links = ""

For i = 1 To Rng.Hyperlinks.Count
    Links = Links + vbNewLine + vbNewLine + Rng.Hyperlinks(i).Address
Next i

MsgBox Links

End Sub

VBA Code to Get Hyperlink From Excel Cell

⧭ Output:

Run the code. It’ll display the hyperlinks from the whole active worksheet.

Read More: Excel VBA: Open Hyperlink in Chrome


Things to Remember

In this article, I’ve focused on getting the hyperlinks from an Excel worksheet only. If you want to know details about the properties and methods of hyperlinks in Excel VBA, you can visit this article.


Download Practice Workbook


Conclusion

So these are the ways to get the hyperlinks from an Excel cell or a range of cells with VBA in Excel. Do you have any questions? Feel free to ask us.

What is ExcelDemy?

ExcelDemy - Learn Excel & Get Excel Solutions Center provides online Excel training , Excel consultancy services , free Excel tutorials, free support , and free Excel Templates for Excel professionals and businesses. Feel free to contact us with your Excel problems.
Rifat Hassan
Rifat Hassan

Rifat Hassan, BSc, Electrical and Electronic Engineering, Bangladesh University of Engineering and Technology, has worked with the ExcelDemy project for almost 2 years. Within these 2 years, he has written over 250 articles. He has also conducted a few Boot Camp sessions on effective coding, especially Visual Basic for Applications (VBA). Currently, he is working as a Software Developer to develop and deploy additional add-ins to enhance the customers with a more sophisticated experience with Microsoft Office Suits,... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo