12 Sept 2011

Search Google Definition for Words in an Excel-File Using VBA

I have a glossary of words held in an excel-workbook. For getting instant definitions from Google I wrote a small macro which does this for me with one click.

This is how it is done:


1. Insert a command-button from the control toolbox (view / toolbars / control toolbox)
2. Double cllick the command button & within the Visual Basic editor insert the below code.

'Info: Macro that searches Google for a definition
'for the word in the active cell.
'Usage: With mouse select cell with word to be
'defined/searched, then hit the button.

Private Sub CommandButton1_Click()
    Dim mystr As String
    mystring = ActiveCell.Value
    mylink = "http://www.google.at/search?q=define%3A+" & mystring
    ThisWorkbook.FollowHyperlink (mylink)
End Sub

3. In design mode add captation, re-size, place, format your button, etc.
4. Exit design mode.
5. Your finished..



ps: you could also do this using the xls-function Hyperlink() but as you may have noticed, saving xls-files containing this function causes some trouble (warning messages, large storage..)

No comments :

Post a Comment