Requirement:
Code below only opens the kind of hyperlinks that are manually put into cells by right clicking cell through Insert Hyperlink step. But the user needs code which will open the kind of hyperlinks which are result of a formula, e.g. =HYPERLINK(A1)
Sub OpenMultipleHyperLinks() 'Update 20141124 - https://www.extendoffice.com/documents/excel/2328-excel-open-multiple-hyperlinks.html#a1 Dim xHyperlink As Hyperlink Dim WorkRng As Range On Error Resume Next xTitleId = "Select a range to open" Set WorkRng = Application.Selection Set WorkRng = Application.InputBox("Select a range to open", xTitleId, WorkRng.Address, Type:=8) For Each xHyperlink In WorkRng.Hyperlinks xHyperlink.Follow Next End Sub
Solution:
Option Explicit Sub followLinks() Dim c As Range Dim WorkRng As Range Dim xTitleId As String Dim url As String Dim i As Long xTitleId = "Select a range to open" Set WorkRng = Selection Set WorkRng = Application.InputBox(xTitleId, xTitleId, WorkRng.Address, Type:=8) If Not WorkRng Is Nothing Then For Each c In WorkRng If c.Hyperlinks.Count > 0 Then For i = 1 To c.Hyperlinks.Count c.Hyperlinks(i).Follow Next i ElseIf InStr(1, c.Formula, "HYPERLINK", vbTextCompare) > 0 Then If InStr(1, c.Formula, ",") > 0 Then url = Evaluate(Left(c.Formula, InStr(1, c.Formula, ",") - 1) & ")") Else url = c.Value End If ActiveWorkbook.FollowHyperlink Address:=url End If Next End If End Sub
Obtained from the OzGrid Help Forum.
Solution provided by trunten.
See also: Index to Excel VBA Code and Index to Excel Freebies and Lesson 1 - Excel Fundamentals and Index to how to… providing a range of solutions and Index to new resources and reference sheets
See also:
How to compare two workbooks with multiple sheets and highlighting duplicates |
How to use a macro to copy data from multiple workbooks to one master sheet in another workbook |
How to copy data from multiple workbooks into one |
How to copy the entire sheet and paste as values - running on multiple tabs |
How to select multiple worksheets and copy to desktop folder |
Click here to visit our Free 24/7 Excel/VBA Help Forum where there are thousands of posts you can get information from, or you can join the Forum and post your own questions.