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
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