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
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.
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
â§ 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
â§ 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
- [Fixed!] This Workbook Contains Links to One or More External Sources That Could Be Unsafe
- How to Create a Drop Down List Hyperlink to Another Sheet in Excel
- How to Link Picture to Cell Value in Excel (4 Quick Methods)
- Why Do My Excel Links Keep Breaking? (3 Reasons with Solutions)
- [Fixed!] ‘This workbook contains links to other data sources’ Error in Excel
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
â§ 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
- How to Hyperlink to Cell in Excel (2 Simple Methods)
- Edit Links in Excel (3 Methods)
- How to Create Dynamic Hyperlink in Excel (3 Methods)
- Combine Text And Hyperlink in Excel Cell (2 Methods)
- How to Link a Table in Excel to Another Sheet (2 Easy Ways)
- How to Use CELL Function in Excel (5 Easy Examples)