A
Andreas
Hi all,
I want to conduct automated google searches with keywords that are
saved in column B of my Excel sheet. Now, for each keyword, I would
like to save the "number of results" that Google finds in my Excel
sheet.
Let's assume I start with the keyword "soccer" in cell B2. Then, I
want to have the number of results found by Google saved in cell B3.
Then, Excel should move on to the next row (column B3, and so on).
I've no experience in VBA but I found a code snippet that kind of does
what I want. However, it does not give me the number of results and
does not move on to the next row. But it is a start.
Thanks in advance for your help.
Andreas
Option Explicit
Public Sub GoogleSearch()
'Use and input box for typing in the search words
Dim szSearchWords As String
Dim szResults As String
szSearchWords = Range("B2").Value
If Not Len(szSearchWords) > 0 Then Exit Sub
'Get keywords and validate by adding + for spaces between
szSearchWords = Replace$(szSearchWords, " ", "+")
Dim ie As Object 'InternetExplorer
Set ie = CreateObject("InternetExplorer.Application")
ie.Navigate "http://www.google.com/search?hl=en&q=" & _
szSearchWords & "&meta="
'Loop until the page is fully loaded
Const READYSTATE_COMPLETE = 4
Do Until ie.ReadyState = READYSTATE_COMPLETE
With ie
.Visible = True
End With
Loop
'Explicitly clear memory
Set ie = Nothing
End Sub
I want to conduct automated google searches with keywords that are
saved in column B of my Excel sheet. Now, for each keyword, I would
like to save the "number of results" that Google finds in my Excel
sheet.
Let's assume I start with the keyword "soccer" in cell B2. Then, I
want to have the number of results found by Google saved in cell B3.
Then, Excel should move on to the next row (column B3, and so on).
I've no experience in VBA but I found a code snippet that kind of does
what I want. However, it does not give me the number of results and
does not move on to the next row. But it is a start.
Thanks in advance for your help.
Andreas
Option Explicit
Public Sub GoogleSearch()
'Use and input box for typing in the search words
Dim szSearchWords As String
Dim szResults As String
szSearchWords = Range("B2").Value
If Not Len(szSearchWords) > 0 Then Exit Sub
'Get keywords and validate by adding + for spaces between
szSearchWords = Replace$(szSearchWords, " ", "+")
Dim ie As Object 'InternetExplorer
Set ie = CreateObject("InternetExplorer.Application")
ie.Navigate "http://www.google.com/search?hl=en&q=" & _
szSearchWords & "&meta="
'Loop until the page is fully loaded
Const READYSTATE_COMPLETE = 4
Do Until ie.ReadyState = READYSTATE_COMPLETE
With ie
.Visible = True
End With
Loop
'Explicitly clear memory
Set ie = Nothing
End Sub