BUY EXCEL BOOKS ONLINE: 1. VBA & Macros      2. VBA for Modelers      3. Excel 2013 VBA and Macros     
4. Excel VBA for Dummies      5. Excel with VBA & .NET      6. Mastering VBA      7. Excel 2013 Programming

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.



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?

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 http://shop.ebay.com/?_from=R40&_trksid=m38.l1313&_nkw=" _
& ActiveCell.Value & "&_sacat=See-All-Categories")

End Sub