PShingadia
New Member
- Joined
- Aug 5, 2015
- Messages
- 47
Hi All
I'm relatively new to VBA and been struggling with the following for 2 days without much progress. If anyone can help then you will make someone today really happy!!
I have written a web scrape and got quite far but stuck with an area where I need to loop through multiple links on a site. When you click on the link it brings up another window and from that want to extract some data. This preview window also has a next button which you can click to see the next item data or you can return back to the list of original links and click on those. I would like either to work. That is access the preview window by clicking the first link and then navigate al the others by the 'Next' button or just loop all the list of links and go to the preview window these show up.
The section of code I have for this is:
Dim btnNext As HTMLSelectElement
Set Alllinks = ie.document.getElementsByTagName("A")
For Each Hyperlink In Alllinks
If Hyperlink.innerText = "View" Then
Hyperlink.Click
Application.Wait (Now + TimeValue("00:00:02"))
Do While ie.Busy Or ie.readyState <> 4
DoEvents
Loop
Set btNext = HTML.document.getElementById("btnNext")
btNext.Click
End If
Next Hyperlink
The above works in clicking the first link and showing the preview window but then does not loop around the others nor does it click the next button. It shows an 'Object Required' error message.
From a desperate man please help!!
I'm relatively new to VBA and been struggling with the following for 2 days without much progress. If anyone can help then you will make someone today really happy!!
I have written a web scrape and got quite far but stuck with an area where I need to loop through multiple links on a site. When you click on the link it brings up another window and from that want to extract some data. This preview window also has a next button which you can click to see the next item data or you can return back to the list of original links and click on those. I would like either to work. That is access the preview window by clicking the first link and then navigate al the others by the 'Next' button or just loop all the list of links and go to the preview window these show up.
The section of code I have for this is:
Dim btnNext As HTMLSelectElement
Set Alllinks = ie.document.getElementsByTagName("A")
For Each Hyperlink In Alllinks
If Hyperlink.innerText = "View" Then
Hyperlink.Click
Application.Wait (Now + TimeValue("00:00:02"))
Do While ie.Busy Or ie.readyState <> 4
DoEvents
Loop
Set btNext = HTML.document.getElementById("btnNext")
btNext.Click
End If
Next Hyperlink
The above works in clicking the first link and showing the preview window but then does not loop around the others nor does it click the next button. It shows an 'Object Required' error message.
From a desperate man please help!!