Panagiotis O.
Panagiotis O.

Reputation: 73

Fill a web form via VBA

Intro: I would like first of all to state that I am not comfortable at all when it comes to "HTML". I have done an exhausted web-search of how to accomplish the below described task. (e.g. Retrieving data from the web using vba, https://www.youtube.com/watch?v=kdD2bb4DU6c, https://www.youtube.com/watch?v=GswfT0Mrr5M )

Problem: In summary would like to fill in a website form (about 10^3 times), submit the query and get each result. In order to test it and keep it simple I am testing it for one value. The VBA code that I managed to put together so far is based on what others have done. It opens a new IE window with the desired URL but it does not fill the desired fields with the "test" Permit # (11) and Suffix (R).

Dim HTMLDoc As HTMLDocument
Dim MyBrowser As InternetExplorer

Sub Test()

Dim MyHTML_Element As IHTMLElement
Dim HTMLDoc As HTMLDocument
Dim MyURL As String
On Error GoTo Err_Clear
MyURL = "http://www.dwr.state.co.us/wellpermitsearch/"
''open new explorer
Set MyBrowser = New InternetExplorer
MyBrowser.Silent = True
''navigate to page
MyBrowser.navigate MyURL
MyBrowser.Visible = True
''wait until ready
Do
DoEvents
Loop Until MyBrowser.readyState = READYSTATE_COMPLETE

Set HTMLDoc = MyBrowser.document
''enter permit number and suffix in text box
HTMLDoc.all.txtPermit.Value = "11"
HTMLDoc.all.txtPermitSuf.Value = "R"
'# HTMLDoc.getElementById("txtPermit").attribute.Value = "11"
'# HTMLDoc.getElementById("txtPermitSuf").attribute.Value = "R"
For Each MyHTML_Element In HTMLDoc.getElementsByTagName("input")
'# If MyHTML_Element.ID = "txtPermit" Then MyHTML_Element.Value = "11"
'# If MyHTML_Element.ID = "txtPermitSuf" Then MyHTML_Element.Value = "R"
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

I have also included some commented code " '# " that are other ways that a friend suggested me that might work. Does anyone have any idea what am I missing???

Thank you in advance for your help and time! :)

Upvotes: 2

Views: 5098

Answers (1)

HopAlongPolly
HopAlongPolly

Reputation: 1433

It's your organizations network blocking the traffic

Try a different computer on a different network

Upvotes: 1

Related Questions