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.
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!