Incrementing VBA Range to Retrieve Values from Website

student_4_life

New Member
Joined
Sep 26, 2014
Messages
3
Hello everyone,

I'm trying to retrieve values from websites and enter them into an excel table using VBA.
Column A has URLs
Column B C and D are where I want the info extracted to be stored
The URL varies for every row so I'd like for the VBA to increment the range as it goes through.
My code so far works fine for the first row but gives me an error message "Method 'Navigate' of object 'IWebBrowser2' failed" for any additional row.




Code:
Sub getInfo()
'
' GetInfo Macro
'
' Keyboard Shortcut: Ctrl+k
'


    Dim IE      As Object: Set IE = CreateObject("InternetExplorer.Application")
    Dim ws      As Worksheet: Set ws = ThisWorkbook.Sheets("Sheet1")
    Dim n As Integer
    Dim Country As String
    Dim Category As String
    Dim Network As String
        
    n = 3
    For n = 3 To 6
    With IE
    
  
        .Visible = False
        .navigate ws.Range("A" & n).Value


        Do
            DoEvents
        Loop Until .readyState = 4


    End With
    
    Country = Trim$(IE.document.getElementByID("youtube-user-page-country").innerText)
    Category = Trim$(IE.document.getElementByID("youtube-user-page-channeltype").innerText)
    Network = Trim$(IE.document.getElementByID("youtube-user-page-network").innerText)
    ws.Range("B" & n).Value2 = Country
    ws.Range("C" & n).Value2 = Category
    ws.Range("D" & n).Value2 = Network
    IE.Quit
    Next n
    
End Sub



THANKS!
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.

Forum statistics

Threads
1,223,894
Messages
6,175,254
Members
452,624
Latest member
gregg777

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