3
I’m having difficulty setting up a VBA programming that does a google search. I can’t understand the HTML part.
The idea is to identify the open internet explorer, go to the google page and search for the word "test" in the search.
Follows code:
Dim ie As SHDocVw.InternetExplorer
Dim objShell As Object
Dim objWindow As Object
Dim objItem As Object
Dim objCollection As Object
Sub teste()
Set objShell = CreateObject("Shell.Application")
Set objWindow = objShell.Windows()
For Each objItem In objWindow
If LCase(objItem.FullName Like "*Internet Explorer*") Then
Set ie = objItem
End If
Next objItem
ie.navigate ("https://www.google.com/?gfe_rd=cr&ei=-s-bVf3ZBcf5gASo1oHAAw&gws_rd=ssl")
Do While ie.Busy Or ie.readyState <> 4
DoEvents
Loop '** Wait til page loaded
Set objCollection = ie.document.getElementsByTagName("input")
i = 0
Do While i < objCollection.all.Length
If objCollection.all(i).ID = "q" Then
objCollection.all(i).Value = "teste"
Exit Do
End If
i = i + 1
Loop
End Sub
I think accessing internet explorer like this is risky and inefficient. In addition, accessing the content of the page to perform the search seems too complicated, unnecessarily. Why not use Shell to open the search address
https://www.google.com/search?q={busca}
? Windows will automatically open the default browser window, and a new tab if the browser is open.– RSinohara
What I wanted was to understand the logic of HTML, to use on other sites later.
– rafami
Minto, I think doing this will open windows explorer, regardless of which is the default browser. Still recommend this line.
– RSinohara
What do you mean by html logic? You want to analyze google page html?
– RSinohara
Yes, I am not able to search the fields by html. It would be the same logic to fill in online forms, parse the HTML to identify the field id and use the VBA to fill it.
– rafami