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
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.