I'm using the VBA function InStr to search a LONG string for specific values. The function doesn't seem to work properly - it doesn't find the correct value when it is present and also returns an incorrect position.
The string that I'm searching is the source code of an HTML document. I put the text in a string variable and believe the starting points should work. Any ideas what I'm doing wrong? Here's the code in question:
'******************************************
Set oIE = New SHDocVw.InternetExplorer
oIE.Visible = True
i = 1
'For i = 1 To 20
sURL = Cells(i, 1).Value
oIE.Navigate (sURL)
Do Until oIE.ReadyState = READYSTATE_COMPLETE
DoEvents
Loop
sText = oIE.Document.body.innerhtml
lStart = InStr(1, sText, "Posted")
lEnd = InStr(lStart, sText, "<p>")
sString = Mid$(sText, lStart, lEnd - lStart)
Cells(i, 2).Value = sString
'Next
oIE.Quit
Set oIE = Nothing
'*************************************************
The string that I'm searching is the source code of an HTML document. I put the text in a string variable and believe the starting points should work. Any ideas what I'm doing wrong? Here's the code in question:
'******************************************
Set oIE = New SHDocVw.InternetExplorer
oIE.Visible = True
i = 1
'For i = 1 To 20
sURL = Cells(i, 1).Value
oIE.Navigate (sURL)
Do Until oIE.ReadyState = READYSTATE_COMPLETE
DoEvents
Loop
sText = oIE.Document.body.innerhtml
lStart = InStr(1, sText, "Posted")
lEnd = InStr(lStart, sText, "<p>")
sString = Mid$(sText, lStart, lEnd - lStart)
Cells(i, 2).Value = sString
'Next
oIE.Quit
Set oIE = Nothing
'*************************************************