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 www.ebay.com (or open an entirely new window of ebay.com, if that makes it easier).
3. Paste the data into the search box at www.ebay.com (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. 


Solution: 
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 Ebay.com with Active Cell Value
            .Navigate "http://shop.ebay.com/?_from=R40&_trksid=m38.l1313&_nkw=" _
                       & ActiveCell.Value & "&_sacat=See-All-Categories"
        End With
End Sub

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



Comments

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 www.half.ebay.com instead of www.ebay.com) 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?