下面的行在实时运行时失败,但是当我在此行之前中断应用程序时,它工作正常。
I = InStr(html_document.body.innerHTML, "EPG")
I 是一个 long,已初始化,并且应该可以正常工作。 html_document是IE.document,通过
初始化Set IE = New InternetExplorer
在该行之前放置一个断点使其工作,我会选择正确的字符位置。
在此行后面放置断点,I
保持为 0。
任何想法将不胜感激。
最佳答案
您最好使用 READYSTATE
枚举来检查页面是否已实际加载。
'READYSTATE_UNINITIALIZED = 0
'READYSTATE_LOADING = 1
'READYSTATE_LOADED = 2
'READYSTATE_INTERACTIVE = 3
'READYSTATE_COMPLETE = 4
Dim IE As New InternetExplorer
'// your other code here
IE.Navigate "http://www.google.co.uk"
While IE.ReadyState <> READYSTATE_COMPLETE
DoEvents
Wend
'// Following code will only run once the document has completely loaded.
Set html_document = IE.Document
I = InStr(html_document.body.innerHTML, "EPG")
'// rest of your code here....
关于vba - excel VBA 代码在单步执行时有效,但在实时运行时无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42277526/