0

Inner text under id is not printing.

Sub JJ()

Dim IE As New SHDocVw.InternetExplorer
Dim hdoc As MSHTML.HTMLDocument
Dim HEL, HBE As MSHTML.IHTMLElement
Dim HBEs As MSHTML.IHTMLElementCollection
Dim ha, hb, hc, hd, he, hf, hg, hh, hi, hj As String
Dim i, x As Integer

IE.Visible = True
IE.navigate "https://www.nseindia.com/get-quotes/equity?symbol=MCX"
Do While IE.readyState <> READYSTATE_COMPLETE
Loop

Set hdoc = IE.document
ha = hdoc.getElementById("quoteLtp").innerText

Debug.Print ha
End Sub

Its just showing nothing. Please help me there to solve the problem.

AAdi
  • 15
  • 4
  • Try adding a `DoEvents` inside the while loop like this: `Do While IE.readyState <> READYSTATE_COMPLETE: DoEvents: Loop` – MGP Jun 08 '21 at 06:53

1 Answers1

0

I have add new dim to your code, and it work no issue to extract the value of 1,536, please try and see

Sub JJ()

Dim IE As New SHDocVw.InternetExplorer
Dim hdoc As MSHTML.HTMLDocument
Dim HEL, HBE As MSHTML.IHTMLElement
Dim HBEs As MSHTML.IHTMLElementCollection
Dim ha, hb, hc, hd, he, hf, hg, hh, hi, hj As String
Dim i, x As Integer
Dim HTMLInput As MSHTML.IHTMLElement

IE.Visible = True
IE.navigate "https://www.nseindia.com/get-quotes/equity?symbol=MCX"
Do While IE.readyState <> READYSTATE_COMPLETE
Loop

Set hdoc = IE.document
Set HTMLInput = hdoc.getElementsByClassName("blkbox-whitetxt").Item

Debug.Print HTMLInput.innerText



End Sub

Try run second time if first run provide no result:

enter image description here

Kin Siang
  • 2,644
  • 2
  • 4
  • 8