Hi - I am trying to understand how to interact with the web from VBA Macro. The code below will sometimes simulate inputting "atn x-sight 5" into Google Search and clicking the Google Search button. However, most of the time it does not work. If I step through the code and place the cursor after "atn x-sight 5" in the search box before executing the line "Element.click", it works every time. Please help.
Sub Webscraping()
Dim ie As InternetExplorer
Dim ht As HTMLDocument
Set ie = New InternetExplorer
ie.Visible = True
ie.navigate ("Googledotcom") <=I can't actually type the URL here because I am not allowed according to my membership status
Do Until ie.readyState = READYSTATE_COMPLETE
DoEvents
Loop
Set ht = ie.document
ht.getElementsByName("q")().Value = "atn x-sight 5"
Set elements = ht.getElementsByTagName("input")
For Each element In elements
If element.DefaultValue = "Google Search" Then
element.Click
Exit For
End If
Next
End Sub
Bookmarks