Excel Productivity Guide
Useful Excel Tips | Keyboard Shortcuts | VBA Codes
Download this Free E-Book to take your excel skills to a whole next level using some smart Excel tactics.

Worth $20, Absolutely Free

VBA Code to Search on Google

There are a lot of important things which we all do other than using Excel.

Am I right?

One of those things is using Google to search for something.

In my list of useful macro codes, I have a code which you can use to perform a search query on Google using Chrome.

And today, I’m gonna share that code with you.

You can add this code to your personal macro workbook and use it anytime when you need to search for something on Google.

VBA Code to Open Google Chrome for Search

Here is the code below which you can use to search on Google using Chrome.

Window 32 Version

Sub SearchWindow32()
Dim chromePath As String
Dim search_string As String
Dim query As String
query = InputBox("Enter here your search here", "Google Search")
search_string = query
search_string = Replace(search_string, " ", "+")
'Uncomment the following line for Windows 64 versions and comment out Windows 32 versions'
chromePath = "C:Program FilesGoogleChromeApplicationchrome.exe"
'Uncomment the following line for Windows 32 versions and comment out Windows 64 versions
chromePath = "C:Program Files (x86)GoogleChromeApplicationchrome.exe"
Shell (chromePath & " -url http://google.com/#q=" & search_string)
End Sub

Window 64 Version

Sub SearchWindow64()
Dim chromePath As String
Dim search_string As String
Dim query As String
query = InputBox("Enter here your search here", "Google Search")
search_string = query
search_string = Replace(search_string, " ", "+")
'Uncomment the following line for Windows 64 versions and comment out Windows 32 versions
chromePath = "C:Program FilesGoogleChromeApplicationchrome.exe"
'Uncomment the following line for Windows 32 versions and comment out Windows 64 versions
'chromePath = "C:Program Files (x86)GoogleChromeApplicationchrome.exe"
Shell (chromePath & " -url http://google.com/#q=" & search_string)
End Sub

How to use this VBA Code to Search on Google

Here are the simple step you need to follow to use this code.

  • ​Open VB editor using shortcut key Alt + F11 or go to developer tab.
  • Insert a new module in and paste above code into it.  

Now, close VB editor and run this macro from macros option in developer tab.

How it works

When you run this code it shows you an input box to enter your query. And you need to enter your query in that input box and click OK.

Once you click OK, this code creates a search URL syntax using the text you have entered.

And, in the end redirects Chrome to that URL to give you result for query you have entered.

Sample File

Download this sample file from here to try it your self.

More VBA Codes to Try

  1. ON-OFF Button in Excel
  2. Internet Radio in Excel
  3. A List of 100 Macro Codes
  4. Create Table of Content
  5. Macro Code To Create a Pivot Table 
  • Pankaj Bahuguna

    this code is having error in last line Shell (chromePath & ” -url http://google.com/#q=” & search_string)