How Can I Use VBA To Access A WebPage (IHTMLDocument?)
10,785
In Internet Explorer, you can simply click a link via the DOM API.
Retrieve the DOM node (the A
) you are interested in, and call click()
on it. This will also fire all associated event handlers.
EDIT: In your case, with VBA, do something like this (untested, I don't have VBA here)
Dim sideNav As IHTMLElement
Dim navLinks As IHTMLElementCollection
Dim currLink As IHTMLElement
Set sideNav = IE.document.getElementByID("sln")
Set navLinks = sideNav.all.tags("A")
For Each currLink In navLinks
If Trim(currLink.innerText) = "Boxing/UFC" Then
currLink.Click
End If
Next currLink
Related videos on Youtube
Author by
Jason
Updated on June 04, 2022Comments
-
Jason almost 2 years
Using the following code, I can open up an Internet Explorer window and navigate to the website. I would like to go further by being able to have a code click through one of the links (such as "Boxing/UFC").
Sub Run() Set IE = CreateObject("InternetExplorer.Application") With IE .Visible = True .Navigate2 "http://www.bet365.com" Do Until .ReadyState = 4: DoEvents: Loop .Quit End With
Because that link leads to a Javascript
onclick
event (onclick="gS(1020,9);return false;"
) can you suggest code I could use that would enable VBA to click through that link without the user's interference once the VBA macro is run?