Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel crashes when calling Doc Readystate

Status
Not open for further replies.

yannickb

Technical User
Sep 1, 2010
4
NL
Hi Everyone,

I Made a VBA Macro for Excel, the VBA script checks several websites for links, source code etc. I get the links out of the source code by doc.Links

Before the source-code is being downloaded I'm checking if the site is completely loaded. I perform this check by the following code:
Code:
While ((doc.readyState <> "complete"))
     DoEvents
Wend

With hundreds of websites this is working correct, but several websites doesn't give a 'Complete'-status back. So i started to search for a solution which could fix this and added the following code:
Code:
            Start = Timer

            While ((doc.readyState <> "complete"))
                If ((Timer - Start) > 30) Then
                     ' Voer actie uit
                Else
                     DoEvents
                End if
             Wend

So after 30 seconds the script would continue, but strangly enough several websites like these:
- -
Keep giving problems, as soon as the script reaches
Code:
While ((doc.readyState <> "complete"))

Excel crashes completely and needs to be restarted, do you have any idea how i could fix this?

Thanks a lot!
Regards Yannick
 
This is the doc-object:
Code:
    Dim d As New MSHTML.HTMLDocument
    Dim doc As HTMLDocument

    Set doc = d.createDocumentFromUrl(urlhun, vbNullString)

After the 'Set doc' part the readystate check is being performed.
 
Hi, does anyone now the answer to my question?
 


Hi,

I know ABSOLUTELY NOTHING about this issue. However values like this...
Code:
While ((doc.readyState <> [b]"complete"[/b]))
are almost always NUMERIC.

If I were a betting man, I'd guess that this perhaps, maybe, might work...
Code:
While ((doc.readyState <> [b]0[/b]))
I'd put a break in my code and use the Watch Window to observe the ACTUAL VALUE of doc.ReadyState

faq707-4594

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
readystate is definitely a string, but I had to look that up. It's in the Microsoft HTML Object Library.

I do some Asynchronous browser manipulation, and I have primarily used the InternetExplorer.Busy property, like so:

Code:
Private Sub pause(ByRef ieBrowser As InternetExplorer)
Do
    Application.wait [Now()] + TimeValue("00:00:01") / 20
[red]Loop Until ieBrowser.Busy = False[/red]
    Application.wait [Now()] + TimeValue("00:00:01") / 2
End Sub

The first application.wait is unnecessary, but is helpful in reducing resource consumption. The second application.wait is VERY important, because even when the InternetExplorer object returns a Busy state of False, it's still not quite ready. You might be able to coax some functionality of combining the InternetExplorer.Busy and InternetExplorer.ReadyState properties in your logic. If you DO test this, please post back, I haven't had the chance to run any analysis :)

Oh, nearly forgot to mention, make sure you include a reference to Microsoft Internet Controls to access the InternetExplorer object model.
 
Hi everyone,

Sorry for my late answer, i've been practising a lot with my script and i finally found out that Excel already crashes at the:
Code:
Set doc = d.createDocumentFromUrl(url, vbNullString)

part instead of the Doc.readystate, is there an alternative for this function?

Thanks a lot!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top