VBA - Get URL from Google First Result

neodjandre

Well-known Member
Joined
Nov 29, 2006
Messages
950
Office Version
  1. 2019
Platform
  1. Windows
I am trying to use this code to get the official website of each company (names in column B). However the output is always a consent URL from google. Any other ways of going about this?

Rich (BB code):
Private Sub FeelingLucky()
    Dim i As Long
    Dim IE As Object
       
    Set IE = CreateObject("InternetExplorer.Application")
    IE.Visible = False
      
    For i = 2 To WorksheetFunction.CountA(Range("B:B"))
        IE.Navigate "http://www.google.com/search?ie=UTF-8&oe=UTF-8&sourceid=navclient&gfns=1&q=" & Cells(i, 2)
        Do While IE.Busy
            Application.Wait DateAdd("s", 1, Now)
        Loop
  
        Cells(i, 3) = IE.Document.Url
    Next i
  
    IE.Quit
  
End Sub
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
There are two issues. Internet Explorer no longer exists for Mac OS. The other is that Apple does not allow Mac applications to start and run other applications. You might be able to use AppleScript and MacScript to accomplish your goal.
 
Upvote 0

Forum statistics

Threads
1,223,941
Messages
6,175,535
Members
452,652
Latest member
eduedu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top