I have a webpage: https://www.brcdirectory.com/InternalSite/Site.aspx?BrcSiteCode=1832583
I want to retrieve some text from this page, from within a HTML <Span ID>
.
<span id="ctl00_ContentPlaceHolder1_FormView1_GridView1_ctl02_lb_ExpiryDate">Expiry Date : 07/12/2017</span>
I have IE 11.0.9600.18639
Via Excel, I am using the below code to open IE 11, navigate to the page and want to try and display a message box of the text inside the <SPAN>
.
Code:
Option Explicit
Sub GoToWebsiteTest()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim appIE As Object
Dim objElement As Object
Dim objCollection As Object
Dim i As Long, LastRow As Long, sFolder As String
Dim sURL As String, FILE As String
LastRow = Range("I" & Rows.Count).End(xlUp).Row
For i = 6 To LastRow
Set appIE = New InternetExplorerMedium
sURL = "https://www.brcdirectory.com/InternalSite/Site.aspx?BrcSiteCode=" & Range("I392").Value
With appIE
.navigate sURL
.Visible = True
End With
Do While appIE.Busy Or appIE.READYSTATE <> READYSTATE_COMPLETE
DoEvents
Loop
Set objCollection = appIE.document.getElementById("ctl00_ContentPlaceHolder1_FormView1_GridView1_ctl02_lb_ExpiryDate")
MsgBox Replace(objCollection.innerText, "Expiry Date : ", "")
appIE.Quit
Set appIE = Nothing
Next i
Application.ScreenUpdating = True
Application.DisplayAlerts = True
MsgBox "All BRCs Succesfully Updated."
End Sub
I have tried everything! I have tried so many variations of this line where I get the error:
Do While appIE.Busy Or appIE.READYSTATE <> READYSTATE_COMPLETE
But alas I get this annoying error:
Runtime Error: -2147467259 (80004005)
Method 'Busy' of object 'IWebBrowser2' failed.
Please, please can someone show me what i am doing wrong. This is driving me crazy. Thanks in advance.