VLAD_BASHAROV
New Member
- Joined
- Jun 26, 2022
- Messages
- 1
- Office Version
- 365
- Platform
- Windows
Hello.
I have a list of Companies and I need do find their type of business. I decided to scrap this info from Google Search using getElementsByClassName. So, My VBA-Code is supposed to google every Company from list, then insert in next cell Innertext. But it doesn't work - every time i see a Run-time Error '91': Object variable or with block variable not set.
Help please - Could someone please have a look.
Thanks
Below - the List of Companies
I have a list of Companies and I need do find their type of business. I decided to scrap this info from Google Search using getElementsByClassName. So, My VBA-Code is supposed to google every Company from list, then insert in next cell Innertext. But it doesn't work - every time i see a Run-time Error '91': Object variable or with block variable not set.
Help please - Could someone please have a look.
Thanks
Below - the List of Companies
TET-A-TET |
CONOCO |
NETCOST |
MARSHALLS |
LUXDEN BROOKLYN |
MILLHOUSE LOGIST |
WAL-MART |
VBA Code:
Private Sub H_CLICK()
Dim QUERY As String
QUERY = ActiveCell
Dim website As String
Dim search_string As String
Dim ie As Object
Dim name As String
Do Until IsEmpty(ActiveCell)
ActiveCell.Offset(0, 1).Value = "RUNNING"
search_string = Replace(QUERY, " ", "+")
website = "https://www.google.com/search?hl=en&ie=UTF-8&q=" & search_string
Set ie = CreateObject("InternetExplorer.Application")
With ie
.Visible = 0
.navigate website
While .Busy Or .readyState <> 4
DoEvents
Wend
End With
Dim Doc As HTMLDocument
Set Doc = ie.document
ActiveCell.Offset(0, 1).Value = "ERROR"
name = Trim(Doc.getElementsByClassName("YhemCb")(2).innerText)
ActiveCell.Offset(0, 1).Value = name
ie.Quit
Loop
End Sub