I would like to open a document containing a number of formfields, select
one of them and use its contents as parameters for a Google search. All this
should happen via a mouse on a button located on a command bar. Is this
possible?
Thanks for any tips.
Gordon Filby
This might be a bit over-engineered :-) but it does work. Put the macro into
your template, and assign a toolbar button to run the macro. It will fire a
Google search for the contents of whatever formfield has the focus.
Sub GoogleIt()
Dim SearchTerms As String
Dim oFld As FormField
Dim oHyper As Hyperlink
On Error GoTo badfield
For Each oFld In ActiveDocument.FormFields
If Selection.Range.InRange(oFld.Range) Then
SearchTerms = oFld.Result
Exit For
End If
Next oFld
If SearchTerms <> "" Then
Set oHyper = ActiveDocument.Hyperlinks.Add( _
Anchor:=ActiveDocument.Range, _
Address:="http://www.google.com/search?q=" & SearchTerms)
oHyper.Follow
oHyper.Delete
End If
badfield:
End Sub
--
Regards,
Jay Freedman
Microsoft Word MVP Word MVP FAQ site: http://www.mvps.org/word
To find only German language pages, change the Address parameter of the
hyperlink this way:
Address:="http://www.google.com/search?q=" _
& SearchTerms & "&lr=lang_de")
Gordon Filby wrote by email:
> Thanks - that is just what I needed. Another question in this context in
> Address:="http://www.google.com/search?q=" & SearchTerms) do you
> know how to restrict the search only to German language pages. Google
> allows this in its special config. page.
--
Regards,
Jay Freedman
Microsoft Word MVP Word MVP FAQ site: http://www.mvps.org/word