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

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
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,224,920
Messages
6,181,768
Members
453,065
Latest member
jfrsanders

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