I'm trying to implement a Google Search method using VBA in Excel. I would like type certain word/words in the pop-up window, whereupon it Google searches the word/words another predetermined phrase. For example, If I type in the pop-up window "John Doe", I would like the Google search to be "John Doe License and Registration", without having to type "License and Registration" everytime I type in a certain name. I'm stuck and don't really know how to add the "License and Registration" in my code.
Private Sub CommandButtonSearch_Click()
Dim query As String
Dim search_string As String
Dim googleChromePath As String
query = InputBox("Enter your keyword", "Google Search")
search_string = Replace(query, " ", " ")
googleChromePath = "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
Shell (googleChromePath & " -url http://google.com/search?q=" & search_string)
End Sub
This picture illustrates how it looks right now: https://i.imgur.com/J2Xrk8l.png
And this picture illustrates how I would like it to look: https://i.imgur.com/iZKyxr1.png
Thank you very much for all the help I can get!
CodePudding user response:
Private Const LicenseRegistration As String = " License and Registration"
Private Sub CommandButtonSearch_Click()
Dim query As String
Dim search_string As String
Dim googleChromePath As String
query = InputBox("Enter your keyword", "Google Search")
search_string = Replace(query, " ", " ") & LicenseRegistration
googleChromePath = "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
Shell (googleChromePath & " -url http://google.com/search?q=" & search_string)
End Sub