Solved

Google result count to Excel (VBA)

Posted on 2012-03-31
7
278 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
ID: 37791515
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
ID: 37791524
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
ID: 37791534
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:kwieckii
ID: 37791584
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
ID: 37791618
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
ID: 38059204
Did you ever find a solution?  I would be interested too.
0
 

Author Comment

by:kwieckii
ID: 39239886
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

920 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

15 Experts available now in Live!

Get 1:1 Help Now