Solved

Google result count to Excel (VBA)

Posted on 2012-03-31
7
274 Views
Last Modified: 2013-06-11
Hello:

I have a list of items in Excel where I need to go to Google and research each item in a cell.  A lot of the items have no results in Google (believe it or not).  

What I'd like to do is to use VBA code to cycle through each row- perform the Google search and in the column next to my research item (in the spreadsheet), include the # of Google results (as shown on the results at the top of a Google search)

I'm hoping this can be done without opening IE each time the search is done.

Is this possible?

Thanks
0
Comment
Question by:kwieckii
  • 3
  • 3
7 Comments
 
LVL 33

Expert Comment

by:Norie
Comment Utility
You could do it with IE, but instead of opening it for each row open it once and just perform the Google Search with the same instance.
0
 

Author Comment

by:kwieckii
Comment Utility
I was hoping I could leverage the Microsoft Internet Controls in the VBA references- and have the results programatically give me all of the result counts directly to Excel.
0
 
LVL 33

Expert Comment

by:Norie
Comment Utility
I don't understand what you mean.

I'm suggesting using code to open one instance of IE then go through the rows doing the search and returning the results to Excel.
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:kwieckii
Comment Utility
Using VBA, I would like to cycle through each row in Column A of Excel and populate Column B with the count of Google results.

Logic of code:

Call Internet Explorer
searchstring = A1              ' A1 = something I need to research - example 'abc incorporated'
open website: google.searchstring                  ' Go to Google with research item
ResultCount = 25,100,000                                    ' Count of Google Results
B1 = ResultCount                                                    ' Populate Cell A2 with result count
Close IE

I have done something similar with translations - translating Spanish to English which called out to Google, translated and then populated the translation to the spreadsheet.

I have only found references to accomplish my new task and haven't been able to refine the code to what I need. - so I'm trying here for a little help  I'm looking for the VBA code that will perform the search for me and return the Google result count to the worksheet.
0
 
LVL 33

Accepted Solution

by:
Norie earned 500 total points
Comment Utility
If you already have code then it shouldn't be too difficult to alter it for this.

This is the code I came up with but it doesn't quite work properly - for some reason the document is empty after the search.
Option Explicit

Sub test()
Dim IE As Object
Dim doc As Object
Dim frm As Object
Dim searchbox As Object
Dim res As Object
Dim strURL As String
Dim rng As Range

    strURL = "http://www.google.com"

    Set rng = Range("A1")


    Set IE = CreateObject("InternetExplorer.Application")


    IE.Navigate strURL

    Do Until IE.ReadyState = 4: DoEvents: Loop
    IE.Visible = True

    While rng.Value <> ""
        Set doc = IE.Document

        Set frm = doc.getElementById("gbqf")

        Set searchbox = doc.getElementById("gbqfq")

        searchbox.Value = rng.Value

        frm.submit

        Do Until IE.ReadyState = 4: DoEvents: Loop
        Set doc = IE.Document
        Set res = doc.getElementById("resultsstat")

        rng.Offset(, 1) = res.innerText

        Set rng = rng.Offset(1)

    Wend
    IE.Quit
End Sub

Open in new window

0
 

Expert Comment

by:jeffreytp11
Comment Utility
Did you ever find a solution?  I would be interested too.
0
 

Author Comment

by:kwieckii
Comment Utility
Sorry for the late response.  The code worked, but I was limited in how many results I was able to send back to Excel.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now