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


Download Practice Workbook

Download this practice workbook to exercise while you are reading this article.


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: How to Create a Hyperlink in Excel (5 Easy Ways)


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: Hyperlink in Excel VBA: Properties and Applications


Similar Readings


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 Hyperlink to Another Sheet Based on Cell Value


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.


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. And don’t forget to visit our site ExcelDemy for more posts and updates.


Related Articles

Rifat Hassan

Rifat Hassan

Hello! Welcome to my profile. Here I will be posting articles related to Microsoft Excel. I am a passionate Electrical Engineer holding a Bachelor’s degree in Electrical and Electronic Engineering from the Bangladesh University of Engineering and Technology. Besides academic studies, I always love to keep pace with the revolution in technology that the world is rushing towards day by day. I am diligent, career-oriented, and ready to cherish knowledge throughout my life.

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo