我使用VBA excel来解析一长串本地.htm
文件。问题是,在程序开始解析HTM文件之前,我甚至都会收到错误。
错误是:
VBA代码:
<!-- language: lang-html -->
Enum READYSTATE
READYSTATE_UNINITIALIZED = 0
READYSTATE_LOADING = 1
READYSTATE_LOADED = 2
READYSTATE_INTERACTIVE = 3
READYSTATE_COMPLETE = 4
End Enum
Sub ImportHTM()
'Dim ie As InternetExplorer
Dim ie As InternetExplorerMedium
Dim html As HTMLDocument
Set ie = New InternetExplorerMedium
'Set ie = New InternetExplorer
ie.Visible = False
ie.navigate "d:\Cloud\Dropbox\3.htm"
Do While ie.READYSTATE <> READYSTATE_COMPLETE
Application.StatusBar = "Loading Profile..." 'PROBLEM SEEMS TO BE HERE SOMEWHERE!
DoEvents
Loop
Set html = ie.document
Set ie = Nothing
Application.StatusBar = ""
'code code code --> which at this point isn't executed because the error occures before
您有什么想法会导致问题吗?你有任何解决方案的建议吗?
还有命令:
ie.Visible = False
似乎没有任何效果,因为它在新的IE窗口中打开HTM文件。
答案 0 :(得分:0)
将状态栏更新移出循环。
Application.StatusBar = "Loading Profile..."
Do While ie.Busy Or ie.READYSTATE <> READYSTATE_COMPLETE
DoEvents
Loop
Application.StatusBar = vbNullString
在等待页面加载时,无需将相同的消息重写为Application.StatusBar property数百(如果不是数千次)。
关于新的Internet.Explorer&#39;窗口&#39;如果没有继承.Visible = False
属性,我建议您切换到.Navigate2和ShellWindows。
附录:在完成与ie
相关联的html
之前,不要销毁ie.document
个对象。