?
Solved

Searching the Internet via VBA for Word

Posted on 2003-02-26
5
Medium Priority
?
173 Views
Last Modified: 2010-04-17
I have a macro recorded in VBA for Word.  When the user highlights a word and right clicks ~ they have an option to search the internet.  When they select this option internet explorer opens with the default page = Google.
I am passing the highlighted word to the search function.

Is there any way, I can pass the word into the google text box??

Any help/suggestions appreciated!
0
Comment
Question by:Cbel
  • 3
  • 2
5 Comments
 
LVL 9

Accepted Solution

by:
bhagyesht earned 200 total points
ID: 8032771
'Add the following code in the module before the macro

Private Const SW_SHOWNORMAL = 1
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


' Add the following code inside your function

ShellExecute vbNull, "open", "http://www.google.com/search?hl=en&ie=ISO-8859-1&q=searchWord", "", "", SW_SHOWNORMAL

replace the above 'searchWord' with your searchWord

'this will open google with the search word as a parameter
0
 

Author Comment

by:Cbel
ID: 8037140
Cheers, that worked!
0
 

Author Comment

by:Cbel
ID: 8037285
Actually, it worked in bringing up the google but it is passing the declared string & not its value.

As in: in a word doc I highlight a word, right click & click "Search", i am passing the highlighted word in a string to the code behind Search.
But its searching for strSel as opposed to its value.

I tried getting the value of is as follows but that doesn't work either.

ShellExecute vbNull, "open", "http://www.google.ie/search?hl=en&ie=ISO-8859-1&q=" & "'&strSel&'", "", "", SW_SHOWNORMAL

Any suggestions?

0
 

Author Comment

by:Cbel
ID: 8037311
Actually, it worked in bringing up the google but it is passing the declared string & not its value.

As in: in a word doc I highlight a word, right click & click "Search", i am passing the highlighted word in a string to the code behind Search.
But its searching for strSel as opposed to its value.

I tried getting the value of is as follows but that doesn't work either.

ShellExecute vbNull, "open", "http://www.google.ie/search?hl=en&ie=ISO-8859-1&q=" & "'&strSel&'", "", "", SW_SHOWNORMAL

Any suggestions?

0
 
LVL 9

Expert Comment

by:bhagyesht
ID: 8039381
thats because you are passing the strSel in quotes
change the line from
ShellExecute vbNull, "open", "http://www.google.ie/search?hl=en&ie=ISO-8859-1&q=" & "'&strSel&'", "", "", SW_SHOWNORMAL

to

ShellExecute vbNull, "open", "http://www.google.ie/search?hl=en&ie=ISO-8859-1&q=" & strSel, "", "", SW_SHOWNORMAL
 and it should work
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
When you discover the power of the R programming language, you are going to wonder how you ever lived without it! Learn why the language merits a place in your programming arsenal.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question