Solved

Google result count to Excel (VBA)

Posted on 2012-03-31
7
292 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

730 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