获取对Internet Explorer文档对象的引用

时间:2017-01-21 07:17:37

标签: excel vba internet-explorer runtime-error browser-automation

我想使用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

我想使用intellisense这就是为什么而不是去ie.document.get我正在使用这种方法。

得到这样的错误:

enter image description here

1 个答案:

答案 0 :(得分:0)

该问题与intellisense无关。您只需要等到导航完成并且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回答。