Access Search Engines on Browser (Internet Explorer) using VBA/Excel

Query Source   : Excel Macros Google Group
Solution Type   : Internet Explorer and VBA
Query by          : Dave K
Solution by       : Ashish Jain (Microsoft Certified Application Specialist;Lead Trainer, Success Electrons)

Query / Problem:
Is there code that could perform the following:

1. Copy the data that lies in the active cell.
2. Go to an open window (in explorer or mozilla) of (or open an entirely new window of, if that makes it easier).
3. Paste the data into the search box at (which by default is the active field when a new window of ebay is opened)
4. Hit "enter" at ebay to display the search results.

I am new to VBA and computer programming, but any suggestions or guidance you can provide would be very much appreciated. 

1. Press Alt+F11. (To write the macro in Code Editor.)
2. Go to Tools --> References --> Select "Microsoft Internet Controls".

3. Copy-Paste the following code.

Sub Login_EBay()
'Requires Reference to "Microsoft Internet Controls"   
    'Declare Reference to InternetExplorer Object
    Dim MyBrowser As SHDocVw.InternetExplorer
    'Set Reference to InternetExplorer Object
    Set MyBrowser = New SHDocVw.InternetExplorer
        With MyBrowser
        'Make the Browser visible
            .Visible = True
            ' Open with Active Cell Value
            .Navigate "" _
                       & ActiveCell.Value & "&_sacat=See-All-Categories"
        End With
End Sub

4. Now, run this macro as desired and whenever required.


Anonymous said…
Wow. Thanks so much. That is really cool!

I noticed that if I try to simply replace the ebay website with a different website (I meant to say instead of that it only jumps to the webpage, but it doesn't perform the search.

Is there something I need to know that will allow me to use the same macro for other websites?
Anonymous said…
This code works on Chrome and Firefox. No need for Selenium or something to launch it. Just need to change your Browser directory. This code launch Home page as well but I think it is not very troublesome.

Sub SearchOnChromeorFF()

Dim Path As String

Path = "C:\Program Files\Google\Chrome\Application\chrome.exe"

'Or use this path to change your browser to Firefox:

'"C:\Program Files\Mozilla Firefox\firefox.exe"
' or back as above
'"C:\Program Files\Google\Chrome\Application\chrome.exe"

Shell (Path & " -url" _
& ActiveCell.Value & "&_sacat=See-All-Categories")

End Sub