Excel Macro code to VBA Code to Search on Google

Share on facebook
Share on linkedin
Share on email
Share on whatsapp

How to VBA Code to Search on Google in excel sheet through VBA Macro Code

For using this VBA macro code in excel to VBA Code to Search on Google you will have copy below Macro code in Excel Visual Basic Editor
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

Follow this post to learn how to use this VBA code to search on Google.

below code also takes the shell command out, and will open your default browser with the value you entered in your search string.

Sub GoogleSearch()

Dim MyURL 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, ” “, “+”)
MyURL = “https:/google.com/#q=”

ActiveWorkbook.FollowHyperlink Address:=MyURL & search_string
End Sub

How to Search on Google using a VBA Code

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.

What is a Macro Code?

In MS Excel, macro code is a programming code which is written in VBA (Visual Basic for Applications) language.

The idea is to use macro code for automating various activities which you perform manually in Excel, otherwise.

For example, you can use a code to print only a particular range of cells just with a single click instead of selecting the range -> File Tab -> Print -> Print Select -> OK Button.

How to use a Macro Code in Excel

click-on-visual-basic-editor-before-you-use-these-useful-macros-for-excel

  • On the left side in “Project Window”, right click on the name of your workbook and insert a new module.

add-module-to-paste-these-useful-macros-for-excel

  • Just paste your code into the module and close it.

use-useful-macro-codes-examples-by-pasting-them-into-vb-editor

  • Now, go to your developer tab and click on the macro button.

useful-macro-codes-examples-to-use-from-macro-options

  • It will show you a window with a list of the macros you have in your file from where you can run a macro from that list.

useful-macro-codes-examples-list-from-macro-option

 

RECENTLY UPLOADED EXCEL TEMPLATES

Training_Attendance_Sheet_V1.0

Training Attendance Sheet

Whether you’re organizing any training program for an athletic event. A technology course, or a chess tournament, a good attendance …

Download Now
Weekly_Attendance_Sheet_V1.0

Weekly Attendance Sheet

Our “Weekly Attendance Sheet” is simple, compact, and useful an all-purpose attendance tracker. This attendance tracker includes one worksheet with …

Download Now
Student_Attendance_Sheet_Weekly_Monthly

Student Attendance Sheet

These student attendance sheet records is create to help teachers keep track of attendance of their students. There are two …

Download Now
Shift_Planner_with_Attendance_Tracker_Pro-employee

Shift Planner with Tracker

Shift Planner with Tracker for Excel is a powerful spreadsheet that help any Human Resources or operational managers creating their …

Download Now
Employee_Attendance_Tracker_Pro_V2.55

Employee Attendance Tracker

The free employee attendance tracker template is one of my popular excel templates. I have create a more general employee …

Download Now
Islamic_Calendar

Islamic Calendar

The Islamic calendar (it is known also as Muslim calendar or Hijri calendar) is a lunar calendar based on 12 …

Download Now