Sub SearchSelectedTextWithQuotes()
Dim selectedText As String
Dim searchQuery As String
Dim searchURL As String
' Get the selected text
selectedText = Trim(Selection.Text)
' Check if there's any text selected
If Len(selectedText) = 0 Then
MsgBox "Please select some text to search.", vbExclamation
Exit Sub
End If
' Wrap the text in quotes and encode for URL
searchQuery = Chr(34) & selectedText & Chr(34)
searchQuery = Replace(searchQuery, " ", "+")
searchQuery = Replace(searchQuery, Chr(34), "%22")
' Construct the search URL
searchURL = "https://www.google.com/search?q=" & searchQuery
' Open the default browser with the search URL
Shell "cmd /c start " & searchURL, vbHide
End Sub
Getting that into your Normal.dotm template so it always appears may be some work.
No comments:
Post a Comment