Word macro for Google search
Thread poster: Samuel Murray
Samuel Murray
Samuel Murray  Identity Verified
Netherlands
Local time: 14:53
Member (2006)
English to Afrikaans
+ ...
Jul 3, 2019

Hello everyone

Does anyone know of a Word macro that can be used to send the currently selected text to the browser as a Google search? I'm looking specifically for a Word macro and not for e.g. an AU3 or AHK script.

Thanks
Samuel

==


 
wotswot
wotswot  Identity Verified
France
Local time: 14:53
Member (2011)
French to English
Here's the code you need Jul 3, 2019

Create a module in VBA (in a .dotm file or your normal.dot(m), if you have one)
In the new module, copy everything below the dotted line exactly as is.
(You may want to localize the google url)
Select some text in Word
Run the macro (only tested in Windows 7)
-------------------------------------------------

Option Explicit
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As Strin
... See more
Create a module in VBA (in a .dotm file or your normal.dot(m), if you have one)
In the new module, copy everything below the dotted line exactly as is.
(You may want to localize the google url)
Select some text in Word
Run the macro (only tested in Windows 7)
-------------------------------------------------

Option Explicit
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

Public Sub GoogleSearch() 'You can assign this macro to a function key if you want
Dim T As String
If Len(Trim(Selection.Text)) > 1 Then 'There must be some text selected in Word
T = Selection.Text
T = Replace(T, " ", "+") 'Words in the query's text must be separated by '+'
OpenURL "http://www.google.com/search?as_epq=" & T 'the as_epq parameter means results must include the query,
'in the word order displayed.
'see the link below for a full list of google search URL parameters
'https://moz.com/blog/the-ultimate-guide-to-the-google-search-parameters
End If
End Sub

Private Function OpenURL(ByVal URLString As String)
ShellExecute 0, "open", URLString, 0, 0, 1
End Function
Collapse


 


To report site rules violations or get help, contact a site moderator:


You can also contact site staff by submitting a support request »

Word macro for Google search






Trados Studio 2022 Freelance
The leading translation software used by over 270,000 translators.

Designed with your feedback in mind, Trados Studio 2022 delivers an unrivalled, powerful desktop and cloud solution, empowering you to work in the most efficient and cost-effective way.

More info »
CafeTran Espresso
You've never met a CAT tool this clever!

Translate faster & easier, using a sophisticated CAT tool built by a translator / developer. Accept jobs from clients who use Trados, MemoQ, Wordfast & major CAT tools. Download and start using CafeTran Espresso -- for free

Buy now! »