standenman
Programmer
I am trying to automate the completion and submission of a series of html forms in VBA. I am able to open the login form, automate the completion of the userID and Password fields as well as check a "disclosure" type checkbox, and clicking the submit button, which brings me to form 2. form 2 has no data to complete, All I need to do is click a button on form 2. I can't get that button to fire for anything. Consistent error 424 or error 91 and I have commented those problems in the code below.
So I am new to this, and really don't know what I am doing, but I am thinking its because I am not actually on form 2 when I reach the code trying to click . Though when the code reaches ieapp.visable = true I do get form1, then form 2 visable, I feel like ieapp may still be pointing to form 1, because when I add iapp.refresh, I am back to form 1, with no info in the userid and password fields of form 1. It seems to me that form 1 has been refreshed.
Here's the form 2 button I want to click: <input name="enterERE" class="uef-btn" id="enterere" type="submit" value="Enter ERE">
Here's my VBA code :
Private Sub ERE_Reports_Click()
Dim ieApp As InternetExplorer
Dim iePage As HTMLDocument
Dim Btn As HTMLFormElement
Set ieApp = New InternetExplorer
ieApp.Navigate "
'wait for page to load
Do Until ieApp.ReadyState = READYSTATE_COMPLETE
Loop
iePage.Forms(0).Item("userid").Value = "UserID"
iePage.Forms(0).Item("password").Value = "Password"
iePage.Forms(0).Item("accept").Click
iePage.Forms(0).submit
Do Until ieApp.ReadyState = READYSTATE_COMPLETE
Loop
ieApp.Visible = True
'this means I am back on form 1 with no info in the userid and password fields
ieApp.Refresh2
'render error 13
Set Btn = iePage.getElementsByName("enterERE")
Btn.Click
'renders error 91
iePage.getElementsByName("EnterERE").Item.Click
'renders error 91
iePage.getElementById("enterere").Click
'iePage.getElementsByClassName("uef-btn").Item.Click
'renders error 424
iePage.Forms(0).Item("enter ere").Click
'render error 438
iePage.getElementsByTagName("enterERE").Click
End Sub
So I am new to this, and really don't know what I am doing, but I am thinking its because I am not actually on form 2 when I reach the code trying to click . Though when the code reaches ieapp.visable = true I do get form1, then form 2 visable, I feel like ieapp may still be pointing to form 1, because when I add iapp.refresh, I am back to form 1, with no info in the userid and password fields of form 1. It seems to me that form 1 has been refreshed.
Here's the form 2 button I want to click: <input name="enterERE" class="uef-btn" id="enterere" type="submit" value="Enter ERE">
Here's my VBA code :
Private Sub ERE_Reports_Click()
Dim ieApp As InternetExplorer
Dim iePage As HTMLDocument
Dim Btn As HTMLFormElement
Set ieApp = New InternetExplorer
ieApp.Navigate "
'wait for page to load
Do Until ieApp.ReadyState = READYSTATE_COMPLETE
Loop
iePage.Forms(0).Item("userid").Value = "UserID"
iePage.Forms(0).Item("password").Value = "Password"
iePage.Forms(0).Item("accept").Click
iePage.Forms(0).submit
Do Until ieApp.ReadyState = READYSTATE_COMPLETE
Loop
ieApp.Visible = True
'this means I am back on form 1 with no info in the userid and password fields
ieApp.Refresh2
'render error 13
Set Btn = iePage.getElementsByName("enterERE")
Btn.Click
'renders error 91
iePage.getElementsByName("EnterERE").Item.Click
'renders error 91
iePage.getElementById("enterere").Click
'iePage.getElementsByClassName("uef-btn").Item.Click
'renders error 424
iePage.Forms(0).Item("enter ere").Click
'render error 438
iePage.getElementsByTagName("enterERE").Click
End Sub