Hyperlink Looping Problem

Blackvader

New Member
Joined
Apr 19, 2023
Messages
1
Office Version
  1. 2021
Platform
  1. Windows
I have the following code which is supposed to loop through the links in a column, click each link and then proceed to the next row in that column. Except that, it isn't working. Any suggestions?
VBA Code:
Sub tumanaliz()
    Dim lastRow As Long
    Dim hyperlink As hyperlink
    
    With Sheets("Listing")
        lastRow = .Cells(.Rows.Count, "I").End(xlUp).Row
        
        For i = 2 To lastRow
            Set hyperlink = .Cells(i, "I").Hyperlinks(1)
            
            If Not hyperlink Is Nothing Then
                Application.StatusBar = "Processing row " & i
                .Cells(2, 32).Value = .Cells(i, 30).Value ' Set value in cell AG2
                
                hyperlink.Follow ' Click on the hyperlink
                
                Application.Wait (Now + TimeValue("0:00:02")) ' Wait for 2 seconds
                
                Application.StatusBar = ""
            End If
        Next i
    End With
End Sub
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
This works for me. I put the hyperlinks column "header" into cell C1 and there are two links in cells C2 and C3 below it which are followed as expected.

VBA Code:
Sub tumanaliz()
    Dim lastRow As Long
    Dim hyperlink As hyperlink
    Dim iLoopIndex As Long
    
    With Sheets("Listing")
        lastRow = .Cells(.Rows.Count, "C").End(xlUp).Row

        For iLoopIndex = 2 To lastRow
            
            Set hyperlink = .Cells(iLoopIndex, "C").Hyperlinks(1)

            If Not hyperlink Is Nothing Then
                Application.StatusBar = "Processing row " & iLoopIndex
                .Cells(2, 32).Value = .Cells(iLoopIndex, 30).Value ' Set value in cell AG2

                hyperlink.Follow ' Click on the hyperlink

                Application.Wait (Now + TimeValue("0:00:02")) ' Wait for 2 seconds

                Application.StatusBar = ""
            End If
        Next iLoopIndex
    End With
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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