Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

start google search from formfield content?

7 views
Skip to first unread message

Gordon Filby

unread,
May 28, 2003, 3:51:53 AM5/28/03
to
Hi,

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


Jay Freedman

unread,
May 28, 2003, 12:37:38 PM5/28/03
to
Hi, Gordon,

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

Jay Freedman

unread,
Jun 2, 2003, 12:15:36 PM6/2/03
to
[replied and posted to the microsoft.public.word.vba.general newsgroup]

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

0 new messages