PDA

View Full Version : Click on "Run Report" Button in IE 11 Webpage using VBA



coooky87
07-09-2017, 11:34 PM
Hi there,
First post and new to VBA, so still learning. I also hope Im posting in the correct area.
here goes....

I have some code here that opens a webpage in IE from EXCEL , inputs "username" and "password" and then directs me to another page which I can then manually run a report from by clicking a button on the web page named "Run Report".
I am looking for some code that will click the "Run Report" button automatically after the below code has run.
I haven't entered the URL we use in the below code as its a confidential one, hope that doesn't set this back at all.
I have also added the source code from the button in IE... <div class="image" id="runButton" onclick="newWindow = false;runOp('RUN:here')" alt="Run Report">Run Report</div>



Dim HTMLDoc As HTMLDocument
Dim MyBrowser As InternetExplorer
Sub Test()


Dim MyHTML_Element As IHTMLElement
Dim MyURL As String
On Error GoTo Err_Clear
MyURL = "enter URL"
Set MyBrowser = New InternetExplorer
MyBrowser.Silent = True
MyBrowser.navigate MyURL
MyBrowser.Visible = True
Do
Loop Until MyBrowser.readyState = READYSTATE_COMPLETE
Set HTMLDoc = MyBrowser.document
HTMLDoc.all.Email.Value = "email address"
HTMLDoc.all.Password.Value = "password"
For Each MyHTML_Element In HTMLDoc.getElementsByTagName("input")
If MyHTML_Element.Type = "submit" Then MyHTML_Element.Click: Exit For
Next
Err_Clear:
If Err <> 0 Then
Err.Clear
Resume Next
End If
End Sub

Any help appreciated..