Getting an error message on this line doc.getElementById("result-stats").innerText while pulling the data from google

Ankitsingh

New Member
Joined
May 16, 2020
Messages
1
Office Version
  1. 2010
Platform
  1. Windows
' HardCode Value, which is alreday define in the code like 4


Sub PullDatafromWeb()
Dim IE As Object
Dim doc As HTMLDocument

Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True

IE.navigate "Google"

Do While IE.Busy Or IE.readyState <> 4
Application.Wait DateAdd("s", 1, Now)
Loop
Set doc = IE.document
doc.getElementsByClassName("gLFyf gsfi")(0).Value = 4
'IE.document.getElementByName("q")(0).Value = 4 'Always Take ID Value from Web Page
'IE.document.getElementById("num2").Value = 4 Or you can use below line after Setting doc Set doc = IE.document
'doc.getElementById("num2").Value = 3

SendKeys "{Enter}"
'doc.getElementsByTagName("div")(1).innerText
StrAdd = doc.getElementById("result-stats").innerText 'Error on this line
'doc.getElementById("resultstats").innerText
' If HTML Page does not have Id then we need to use Class Name
'along with Index,Index always get started with 0
'StrMult = doc.getElementsByClassName("clslbl")(2).innerText

ThisWorkbook.Sheets("Sheet1").Range("C2").Value = StrAdd
'ThisWorkbook.Sheets("Sheet1").Range("D2").Value = StrMult

End Sub
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.

Forum statistics

Threads
1,212,928
Messages
6,110,734
Members
448,294
Latest member
jmjmjmjmjmjm

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