?
Solved

Searching the Internet via VBA for Word

Posted on 2003-02-26
5
Medium Priority
?
171 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Introduction to Processes
Starting up a Project
Suggested Courses
Course of the Month7 days, 20 hours left to enroll

765 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