VBA to open all hyperlinks in an Excel column

chasidar

New Member
Joined
Jan 6, 2011
Messages
18
I have a column (I) of hyperlinks to Google search book titles which are listed in a different column (H). Syntax in column I is: =HYPERLINK("Google" & H2,"Google "&H2). I wanted a VBA which will run through the column and run each search so I don't need to manually. I ran below VBA but the pages that open up are: OneDrive
Any idea why or how to correct?
Sub Open_Link()
Dim iCell As Range

For Each iCell In Range("I1:I60")
If Not IsEmpty(iCell) Then
ThisWorkbook.FollowHyperlink iCell.Value
End If
Next iCell

End Sub
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Untested here. Let me know if this works for you.

VBA Code:
Sub OpenGoogleSearchesInTabs()
    Dim ws As Worksheet
    Dim searchRange As Range
    Dim cell As Range
    Dim link As String
    
    ' Set your worksheet and range
    Set ws = ThisWorkbook.Sheets("Sheet1") ' Change "Sheet1" to your sheet name
    Set searchRange = ws.Range("I2:I" & ws.Cells(ws.Rows.Count, "I").End(xlUp).Row)
    
    ' Loop through each cell in the search range
    For Each cell In searchRange
        If cell.Hyperlinks.Count > 0 Then
            link = cell.Hyperlinks(1).Address
            ' Open the hyperlink in a new browser tab
            Shell "cmd /c start """" """ & link & """", vbNormalFocus
            ' Optional: Wait for a short time before opening the next link
            Application.Wait Now + TimeValue("00:00:01")
        End If
    Next cell
End Sub
 
Upvote 0
Untested here. Let me know if this works for you.

VBA Code:
Sub OpenGoogleSearchesInTabs()
    Dim ws As Worksheet
    Dim searchRange As Range
    Dim cell As Range
    Dim link As String
   
    ' Set your worksheet and range
    Set ws = ThisWorkbook.Sheets("Sheet1") ' Change "Sheet1" to your sheet name
    Set searchRange = ws.Range("I2:I" & ws.Cells(ws.Rows.Count, "I").End(xlUp).Row)
   
    ' Loop through each cell in the search range
    For Each cell In searchRange
        If cell.Hyperlinks.Count > 0 Then
            link = cell.Hyperlinks(1).Address
            ' Open the hyperlink in a new browser tab
            Shell "cmd /c start """" """ & link & """", vbNormalFocus
            ' Optional: Wait for a short time before opening the next link
            Application.Wait Now + TimeValue("00:00:01")
        End If
    Next cell
End Sub
 
Upvote 0
I just had time to test it here. It works.

Paste the macro into a Regular module.

Create a command button on your worksheet. Immediately after pasting the command button a small pop-up window appears. Click on the macro name
"OpenGoogleSearchesInTabs" then click OK.

You can then click the command button to open each of the URLs in your browser.
 
Upvote 0
I just had time to test it here. It works.

Paste the macro into a Regular module.

Create a command button on your worksheet. Immediately after pasting the command button a small pop-up window appears. Click on the macro name
"OpenGoogleSearchesInTabs" then click OK.

You can then click the command button to open each of the URLs in your browser.
I tried with a command button and still nothing happens
 
Upvote 0
Attempting to place your hyperlink in cell H2 creates a circular reference. Something Excel won't tolerate.
Placing your hyperlink in G2 works with the following macro :

VBA Code:
Option Explicit

Sub OpenGoogleSearchesInTabs()
    Dim ws As Worksheet
    Dim searchRange As Range
    Dim cell As Range
    Dim link As String
    
    ' Set your worksheet and range
    Set ws = ThisWorkbook.Sheets("Sheet1") ' Change "Sheet1" to your sheet name
    Set searchRange = ws.Range("G2")
    
    ' Loop through each cell in the search range
    For Each cell In searchRange
        If cell.Hyperlinks.Count > 0 Then
            link = cell.Hyperlinks(1).Address
            ' Open the hyperlink in a new browser tab
            Shell "cmd /c start """" """ & link & """", vbNormalFocus
            ' Optional: Wait for a short time before opening the next link
            Application.Wait Now + TimeValue("00:00:01")
        End If
    Next cell
End Sub

???
 
Upvote 0

Forum statistics

Threads
1,225,488
Messages
6,185,281
Members
453,285
Latest member
Wullay

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top