Reputation: 1
I'm trying to scrape data from web into excel through vba macro. I have a set of search results (eg. from Google scholar) open in IE, after scraping first web page into excel my macro clicks the 'next' button at the bottom of the page and a new page opens in the same tab. However, what i wish is, when my macro clicks on 'next' on the web page, it opens the page in a new tab in the same IE window. Any help is appreciated. Thanks in advance.
My code to click the 'next' hyperlink looks like-
Set Alllinks = .document.getElementsByTagName("a")
For Each Hyperlink In Alllinks
If InStr(Hyperlink.innertext, "Next") > 0 Then
Hyperlink.Click CLng(2048)
Exit For
End If
Next
Upvotes: 0
Views: 398
Reputation: 84465
Navigate to the href of the a
tag. This does this leads to the desired location. If you can provide the actual html/url we can probably remove the loop as well and shorten the code.
Set allLinks = .document.getElementsByTagName("a")
For Each Hyperlink In allLinks
If InStr(Hyperlink.innertext, "Next") > 0 Then
ie.navigate2 Hyperlink.getAttribute("href"), CLng(2048)
Exit For
End If
Next
Upvotes: 1