Emulate button click on web page

P

Paul Martin

I've been able to programmatically click a web page button in VBA by
creating an instantiation of Internet Explorer, but wish to achieve
this without IE. I've got the code working to a point and am stuck.

The code so far is:

Private Const HTTPREQ_SUCCESS As Integer = 200
Private Const HTTP_PATH As String = "http://192.120.13.77/
viewtable.aspx?region=E_AUST&report=int924"

Sub GetHtmlPage()
Dim HttpReq As New MSXML2.XMLHTTP
Dim HtmlDoc As New MSHTML.HTMLDocument
Dim objButton

HttpReq.Open "GET", HTTP_PATH, False
HttpReq.send

If HttpReq.Status = HTTPREQ_SUCCESS Then
HtmlDoc.body.innerHTML = HttpReq.responseText
Debug.Print HtmlDoc.forms("aspnetForm").Name ' Confirm that
we've found the web form

' We'll first get diverted to a disclaimer page and must click
the "I Agree" button.
Set objButton = HtmlDoc.getElementsByName
("ct100_ContentPlaceHolder1_imgAgree")
Debug.Print TypeName(objButton) ' Confirm that we can find
the button
objButton.Click ' ##### THIS FAILS!!! ##############
End If
End Sub

### END OF CODE ###

Note that TypeName(objButton) returns DispHTMLElementCollection but I
can't work out what variable type to declare objButton as.
Note also that objButton.Click fails.

Can anyone suggest what I need to do to progress?

Thanks in advance

Paul Martin
Melbourne, Australia
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top