?
Solved

Google result count to Excel (VBA)

Posted on 2012-03-31
7
Medium Priority
?
312 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 34

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 34

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
Industry Leaders: 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 34

Accepted Solution

by:
Norie earned 2000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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…
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

801 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