Excel VBA “Method 'Document' of object 'IWebBrowser2' failed”

后端 未结 3 2263
独厮守ぢ
独厮守ぢ 2020-11-27 22:48

I\'m trying to automate a form submission in Excel for work, and In have trouble with the basics. I keep getting the error message:

\"Method \'Documen

3条回答
  •  爱一瞬间的悲伤
    2020-11-27 23:41

    I ran into this same issue a while back. Use internet explorer at a medium integrity level. InternetExplorer defaults to a low integrity level which, if you are doing this over a local intranet at work, sometimes will give the second error message you show above. Click here for more reading on this. I've modified your code below. Please let me know if that helps.

    Sub GoToWebsiteTest()
    Dim appIE As InternetExplorerMedium
    'Set appIE = Nothing
    Dim objElement As Object
    Dim objCollection As Object
    
    Set appIE = New InternetExplorerMedium
    sURL = "http://example.com"
    With appIE
        .Navigate sURL
        .Visible = True
    End With
    
    Do While appIE.Busy Or appIE.ReadyState <> 4
        DoEvents
    Loop
    
    Set objCollection = appIE.Document.getElementsByTagName("input")
    
    Set appIE = Nothing
    End Sub
    

    Remember references for Microsoft Internet Controls, and depending on what you plan on doing further, Microsoft HTML Object Library

提交回复
热议问题