0

I created the following program to extract data from website to excel sheet but it's showing error.

Error line:

price = html.getElementById("azimuth").Item(0).innerText"

Error message:

Run Time Error '91': with Object Variable or block variable not set

Novice in VBA.

Sub Get_Web_Data()

Dim request As Object
Dim response As String
Dim html As New HTMLDocument
Dim website As String
Dim price As Variant


website = "https://www.mooncalc.org/#/40.7146,-74.0071,9/2022.04.15/18:30/1/3"

Set request = CreateObject("MSXML2.XMLHTTP")
[enter image description here][1]
request.Open "GET", website, False

request.send

response = StrConv(request.responseBody, vbUnicode)

html.body.innerHTML = response

price = html.getElementById("azimuth").Item(0).innerText

Cells(2, "B") = price

End Sub
James Z
  • 12,209
  • 10
  • 24
  • 44
  • My guess is that there is no element with an ID of `azimuth` that it could find. Try setting that first, and check to see if it has a value or not. – braX Apr 15 '22 at 18:40
  • I guess so but the problem is how do I check to see if it has a value or not? If it does not have one, what should I do to make sure the VBA a success? I do not use IE. I use Google Chrome. Thanks. – Gurunath Tom Apr 15 '22 at 20:57
  • The value shown is calculated by JS using info from additional dynamic XHR requests the page makes. Either replicate that process (if possible) or automate a browser. SeleniumBasic can automate Chrome. Note that the JS calcs are in the source files for the webpage. Start with `function Ha.....H = pa(a, d) - c; azimuth = Math.atan2(Math.sin(H), Math.cos(H) * Math.sin(e) - Math.tan(b) * Math.cos(e));` – QHarr Apr 15 '22 at 21:24

0 Answers0