VBA IE input field fill doesn't work first try, always works second try

travisk1154

New Member
Joined
Jun 15, 2016
Messages
4
Hello,
I have a vba code attached to a button to open a webpage, fill an input field with data from the workbook, and click the submit button. Upon opening the workbook, click the button opens the webpage, but that's it. If you go back and click the button again, it loads the page again, and fills the field, and clicks submit. What would cause it to fail the first time, but not any proceeding times? Thanks in advance. I apologize for not having the code in the standard format, can see to get the mr excel maker to install on the work pc.

Private Sub CommandButton1_Click()
Dim co As String
Dim ie As SHDocVw.InternetExplorer
Set ie = New SHDocVw.InternetExplorer
Dim PauseTime, Start
ie.Visible = True
ie.Navigate "https://synergyagile.powellind.pri/Agile/"
co = "CO-" & Range("AA2").Text


Do
DoEvents
Loop Until ie.ReadyState = 4


'pause for entire page to load completely
PauseTime = 2
Start = Timer
Do While Timer < Start + PauseTime
DoEvents
Loop
'input text
For Each hyper_link In ie.Document.getElementsByTagName("input")
If hyper_link.getAttribute("id") = "QUICKSEARCH_STRING" Then
hyper_link.value = co
Exit For
End If
Next
'click button
For Each hyper_link In ie.Document.getElementsByTagName("a")
If hyper_link.getAttribute("id") = "top_simpleSearch" Then
hyper_link.Click
Exit For
End If
Next

End Sub
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

Forum statistics

Threads
1,223,162
Messages
6,170,431
Members
452,326
Latest member
johnshaji

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