Excel VBA code to click on HTML table in website

Smithy02468

New Member
Joined
Aug 4, 2013
Messages
13
I am accessing a website via excel vba the login process works ok and then produces a HTML table with one row which requires that i click on the cell with North_Yorkshire to enter the website.
1610444085082.png

1610444123267.png


below is the source code for this cell,

<DIV class="x-grid3-cell-inner x-grid3-col-Name" unselectable="on">NORTH_YORKSHIRE</DIV>

Private Sub CommandButton2_Click()

Dim MyHTML_Element As IHTMLElement
Dim Myurl As String
Dim HTMLDoc As MSHTML.HTMLDocument
Dim HTMLInput As MSHTML.IHTMLElement

On Error GoTo Err_Clear

Myurl = "***********************"

Set MyBrowser = New InternetExplorer
MyBrowser.Silent = True
MyBrowser.navigate Myurl
MyBrowser.Visible = True
Do
Loop Until MyBrowser.readyState = READYSTATE_COMPLETE
Set HTMLDoc = MyBrowser.Document

'Checkbox

Set HTMLInput = HTMLDoc.getElementById("chkTermsAndCond")
HTMLInput.Click

'Log in button press

Set HTMLInput = HTMLDoc.getElementById("btnContinue")
HTMLInput.Click

Application.Wait (Now + TimeValue("0:00:05"))

'Login Form
Set HTMLInput = HTMLDoc.getElementById("Username")
HTMLInput.Value = ThisWorkbook.Sheets("Stats").Range("C16").Value
Set HTMLInput = HTMLDoc.getElementById("Password")
HTMLInput.Value = ThisWorkbook.Sheets("Stats").Range("E16").Value

HTMLDoc.getElementById("ext-gen27").Click

'HTML Table
HTMLDoc.getElementsByName("x-grid3-cell-inner x-grid3-col-Name") = "NORTH_YORKSHIRE"

Set HTMLTables = HTMLDoc.getElementsByTagName("")

'Tried using it seems to pause then does nothing
'HTMLDoc.getElementsByClassName("x-grid3-cell-inner x-grid3-col-Name") = "NORTH_YORKSHIRE"
'HTMLInput.Click

Err_Clear:
If Err <> 0 Then
Err.Clear
Resume Next

End If
End Sub


any ideas ?

Thanks in advance for any help

Colin
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
getElementsByName and getElementsByClassName return an array, so you have to specify the array item index in brackets. Assuming the cell you want to click is the first element with the specified class name, maybe:
VBA Code:
Set HTMLInput = HTMLDoc.getElementsByClassName("x-grid3-cell-inner x-grid3-col-Name")(0)
HTMLInput.Click
or try the class name of the preceding TD, ending "cell-first".
 
Upvote 0

Forum statistics

Threads
1,223,891
Messages
6,175,229
Members
452,621
Latest member
Laura_PinksBTHFT

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