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

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
also the above code doesn't seem to be compatible with MAC VBA
 
Upvote 0
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,216,144
Messages
6,129,120
Members
449,488
Latest member
qh017

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