获取引用到Internet Explorer文档对象

问题描述 投票:0回答:1

我想用VBA来访问Internet Explorer中。

Dim ie As InternetExplorer
Dim i As IHTMLDocument
Dim d As HTMLDocument
Set ie = New InternetExplorer
ie.Visible = True
ie.Navigate "www.google.com"
Set d = ie.Document

我想使用智能感知,这就是为什么,而不是去为ie.document.get我使用这种方法。

收到错误是这样的:

enter image description here

excel vba internet-explorer runtime-error browser-automation
1个回答
0
投票

这个问题是不是与智能感知有关。所有你需要的是等待,直到导航结束,IE是访问文件前准备:

Sub Test()

    Dim ie As InternetExplorer
    Dim i As IHTMLDocument
    Dim d As HTMLDocument
    Set ie = New InternetExplorer
    With ie
        .Visible = True
        .Navigate "https://www.google.com"
        Do While .ReadyState < READYSTATE_COMPLETE Or .Busy: DoEvents: Loop
        Set d = .Document
    End With

End Sub

也看看this答案。


推荐问答