Tuesday, September 20, 2011

Search selected term from word doc using your favorite browser and search engine

This macro will help you to search the selected word from word doc directly in google or any other site easily.
No need to copy the text from word open google and paste the word in search box and search.
Its very simple select the text and run the macro your search result will appear in your favorite browser.

Note:
1.Change the Path to your browser (firefox, IE, chrome etc.,) installation path.
2.To search other website change the Link to your favorite search engine.
Code:

*********************************************************************
Sub googlesearch()

Dim x As Variant
Dim Path As String
Dim Link As String
Dim TheTerm As String

If Selection.Type = wdSelectionIP Then
TheTerm = Selection.Words(1).Text
Else
TheTerm = Selection.Text
End If
TheTerm = Trim(TheTerm)

    Path = "C:\Program Files\Mozilla Firefox\firefox.exe"

    'for internet explorer change the path to "C:\Program Files\Internet Explorer\iexplore.exe"

    Link = "http://www.google.com/search?num=20&hl=en&q=" & TheTerm
    'for searching with Bing change the Link to "http://www.bing.com/search?q="

    x = Shell(Path + " " + Link, vbNormalFocus)

End Sub
*********************************************************************

No comments:

Post a Comment