Perform Google Search on Internet Explorer using Excel VBA | Excel VBA

First time in my life I have come across to create this type of automation and finally, I got success.

How to search data in Google using Excel VBA:

For example:

  • Write “Apple” in Google search box

  • Press Enter↵
    It will show you the statistics that how many records it has populated and also how much time it has taken to fetch the records.

Picture-1 Google Search

(Picture 1) Google search using Excel VBA

We will do the same using Excel VBA. Isn’t it interesting? I also didn’t have any idea about it. But by googling I got the idea and learned that you can do almost anything with excel VBA & wanted to share it with you. If you open any page in IE (Internet Explorer) and you press F12 then you will get the HTML of that page. All you need to do is you will have to take the id of the specific box. First Open Google in IE and then press F12. You will move to another HTML page. The page will look like below 

Picture-2 HTML Page

(Picture 2) Google search using Excel VBA

Now Press on the arrow (Red circle in Picture 2). And you are forced to go back to Google page. Then place your on Google search box and then click on the box. As soon as you click on the box again you will be in HTML page and this time, you will get everything of that box like name, title, id etc…

Picture-3 HTML Box

(Picture 3) google search using Excel VBA

Now we need to use the id (“lst-ib”) in our code. And in this way, you will get the id of any DOM object. Sometimes “id” is not available and then we need to use a name in our code. Now you will come to our excel file. We have some inputs in our excel file. All we need to do is we need to open Google and will have to fetch the statistics of the search result. Our input in excel file is like below picture

Picture-4 Input in Excel File

(Picture 4) google search using Excel VBA

Now we will take one by one keyword and search the keyword in Google and after opening the other page we will fetch the result.

Please follow the below steps to get the result:

  1. Open VBA page by pressing ALT + F11

  2. Go to Insert and then Module
  3. Copy the below code and paste in the Module
  4. Go to Tools and then Reference and select all the reference as shown in Picture 5
  5. Run the code by pressing F5 or from Run button

Picture-5 Refrence Box

(Picture 5) google search using Excel VBA

Here is the code 

Sub SearchGoogle()

Dim ie As Object

Dim form As Variant

Dim button As Variant

Dim LR As Integer

Dim var As String

Dim var1 As Object

LR = Cells(Rows.Count, 1).End(xlUp).Row

For x = 2 To LR

var = Cells(x, 1).Value

Set ie = CreateObject("internetexplorer.application")

ie.Visible = True

With ie

.Visible = True

.navigate ""

While Not .readyState = READYSTATE_COMPLETE


End With

'Wait some to time for loading the page

While ie.Busy



Application.Wait (Now + TimeValue("0:00:02"))

ie.document.getElementById("lst-ib").Value = var

'Here we are clicking on search Button

Set form = ie.document.getElementsByTagName("form")

Application.Wait (Now + TimeValue("0:00:02"))

Set button = form(0).onsubmit


'wait for page to load

While ie.Busy



Application.Wait (Now + TimeValue("0:00:02"))

Set var1 = ie.document.getElementById("resultStats")

Cells(x, 2).Value = var1.innerText


Set ie = Nothing

Next x

End Sub

Your code will look like below:

Picture-6 Coding

(Picture 6) google search using Excel VBA

You will notice that the code will open your IE browser in a new window and then search all the keywords one by one and fetch the result and paste the result in excel sheet and when it is done it will close the browser.

Finally when it is done then go back to excel sheet and it will find that it has copied the search result and paste in desired cells.

Picture-7 Answers in Excel Cells


Please download the file from here and go through the code. What I have done is I have created an object called Internet Explorer and then navigating the page to Google. I waited for some time there until and unless this page comes to a ready state and then finally I used the ids to fetch the records. Hope you have learned something new on my blog. Please go through the code and try to understand the logic. Also please let us know your feedback. Your comment will help to write some interesting blogs like this. You can learn more about our Advanced Excel VBA tutorials and Free Excel VBA tutorials

2 Responses

Related Tutorials

Connect to Data in Power Query
February 21, 2019
How to use Text to Column in Excel with 4 Difference Example
February 21, 2019
Things you should learn in Excel Course
February 13, 2019
How to use Clean Function in Excel
February 11, 2019
How to use the Excel Choose Function
February 11, 2019
How to use the Excel Code Function
February 11, 2019
How to use the Excel Column Function
February 11, 2019
How to use Ceiling Function in Excel
January 30, 2019
How to use Char Function in Excel
January 28, 2019
Text To Column in Excel | Split Cells
January 4, 2019
Pivot Tables (Complete Guidelines)
December 27, 2018
Power Bi Dax Deduplication Based On Column
December 17, 2018
Special Character Symbol List with Shortcodes in Excel
December 15, 2018
December 10, 2018
December 10, 2018
How to use ABS Function in Excel
December 10, 2018
How to use AND Function in Excel
December 10, 2018
Delete Duplicate in Excel or Remove Duplicate in Excel
November 9, 2018
Excel Formulas and Functions in PDF
September 6, 2018
How To Lock Cells in Excel | Unprotect Excel
August 13, 2018
4x Faster at Excel
August 6, 2018
Separate Content of One Excel Cells into Separate Columns
August 3, 2018
How to Transpose Excel Columns to Rows | Paste Special Method
July 26, 2018
How to create sparklines in Excel
July 19, 2018
AutoSum in Excel with Shortcut
July 17, 2018