Solved

Google result count to Excel (VBA)

Posted on 2012-03-31
7
285 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

770 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