I am trying to pull a single value from a work website that refreshes every 5 minutes into an Excel cell. This is the final step in automating an entire workbook filled with a bunch of formulas I created. I am using HTTP Get Request to do this. However, I am having problems pulling the actual number I want. It is a span id and it is behind an iFrame element. FlowWidget is the iframe's id. Here is my code I have already. I am new to VBA, so this was a done from a lot of just researching but now I am stuck. Been trying for almost two days now. I have edited it a number of times but with no luck. Now with this one I am getting the error code "object variable or with block variable not set" on the "Set eleNumber" line. Thanks to anyone willing to help. Here is my code.
Sub ScrapInductAmount ()
Dim H As Object, doc As New HTMLDocument, eleNumber As Object
Set H = CreateObject("WinHTTP.WinHTTPRequest.5.1")
URL = "Work URL"
Debug.Print URL
ReTry:
H.SetAutoLogonPolicy 0
H.SetTimeOuts 0, 0, 0, 0
H.Open "GET", URL, False H.send H.WaitForResponse
If H.Status <> 200 Then
MsgBox H.Status & " - " & H.statusText
Exit Sub
End If
Debug.Print H.responseText
doc.Body.innerHTML = H.responseText
Set eleNumber = doc.querySelector("[id='_FlowWidget']").contentDocument.querySelector("span[id=force_induct_count_value]")
Dim inductAmount As String
If Not eleNumber Is Nothing Then inductAmount = eleNumber.innerText
Set doc = Nothing
Range("A1").Value = inductAmount
End Sub
Sub ScrapInductAmount ()
Dim H As Object, doc As New HTMLDocument, eleNumber As Object
Set H = CreateObject("WinHTTP.WinHTTPRequest.5.1")
URL = "Work URL"
Debug.Print URL
ReTry:
H.SetAutoLogonPolicy 0
H.SetTimeOuts 0, 0, 0, 0
H.Open "GET", URL, False H.send H.WaitForResponse
If H.Status <> 200 Then
MsgBox H.Status & " - " & H.statusText
Exit Sub
End If
Debug.Print H.responseText
doc.Body.innerHTML = H.responseText
Set eleNumber = doc.querySelector("[id='_FlowWidget']").contentDocument.querySelector("span[id=force_induct_count_value]")
Dim inductAmount As String
If Not eleNumber Is Nothing Then inductAmount = eleNumber.innerText
Set doc = Nothing
Range("A1").Value = inductAmount
End Sub