Simple IE function, unstable

Jaymond Flurrie

Well-known Member
Joined
Sep 22, 2008
Messages
921
Office Version
  1. 365
Platform
  1. Windows
I have a pretty simple function,

Code:
Function GetTextFromIe(strURI As String) As String
    Dim ie As Object
    Dim objDoc As Object
    Dim strContent As String
    
    Set ie = Nothing
    Set ie = CreateObject("internetexplorer.application")
    
    ie.Navigate strURI
    
    Do
        If ie.ReadyState = 4 Then
            ie.Visible = False
        Exit Do
    Else
    
    DoEvents
        End If
    Loop
    
    Set objDoc = ie.Document
    
    strContent = objDoc.body.outerHTML
    
    Set objDoc = Nothing
    ie.Quit
    Set ie = Nothing
    
    GetTextFromIe = strContent
End Function

Why doesn't strContent always include the whole page? I mean, sometimes the length (len(strContent)) might be even six times longer than other times. And yes, the source page is same (I tried with www.nhl.com) and the source code has a lot more than what this function returns. Is there some timing limits or some other things that are not necessarily obvious?

I've been running this on Excel 2007 on Windows XP. My Internet connection is 100/5 Mb.
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Hi Jaymond, I couldn't replicate your results ??
Got same len every time (89844) .... although I did use your code diff

Code:
Function GetTextFromIe(strURI As String) As String
    Dim ie As Object
    Dim objDoc As Object
    Dim strContent As String
    
    Set ie = Nothing
    Set ie = CreateObject("internetexplorer.application")
    
    ie.Navigate strURI
    ie.Visible = False
    Do
        DoEvents
        If ie.ReadyState = 4 Then Exit Do
    
    Loop
    
    Set objDoc = ie.Document
    
    strContent = objDoc.body.outerHTML
    
    Set objDoc = Nothing
    ie.Quit
    Set ie = Nothing
    
    GetTextFromIe = strContent
End Function
 
Upvote 0

Forum statistics

Threads
1,225,397
Messages
6,184,716
Members
453,254
Latest member
topeb

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top