VBA Internet Explorer Automation 'Permission Denied'

后端 未结 8 1325
别那么骄傲
别那么骄傲 2020-12-19 23:11
Dim IE as New InternetExplorer
IE.Visible = True

IE.Navigate(\"http://www.google.com\")

Do Until IE.Busy = False
Loop

IE.document.getElementsByTagName(\"Input\")(         


        
8条回答
  •  醉话见心
    2020-12-19 23:40

    I had the same Run time error 70. Permission denied when automating a Webbrowser control in VBA under MS Access 2010. My objective was to set innerHTML for a Content Editable node. Initially, it worked perfectly and then for an unknown reason, I started getting "Error 70. Permission Denied." Interestingly, this error seems to come from the IE Web Browser control and not from MS Access. At times, it was not trapped by the VBA error handler, On Error. Another puzzle is that when single stepping through the code, it would work, but when running normally, the Webbrowser control would just not function, but not raise an error. However, it would raise an error if I set a break point and then queried the WebBrowser in the immediate pane on VBA with code such as: ? DIV.innerHTML

    Here is the code that failed:

    Private Function SetInnerHTML(HTML As String) As String
    Dim HTMLEmail As HTMLDocument
    Dim DIV As HTMLDivElement
    Set HTMLEmail = Me.Email_MainBrowser.Controls("MyBrowser").Object.Document
    Set DIV = HTMLEmail.getElementById("MyText")
    DIV.innerHTML = HTML ' This is the line that failed
    

    Like Dennis, the OP, I tried adding in Sleep calls and added in function calls to make sure the Browser returned "Ready State" CurrentState = Me.Form("Email_MainBrowser").Controls("MyBrowser").ReadyState (CurrentState should be acComplete).

    Here are the things I tried which did not solve the problem: 1) Decompile and recompile the MS Access application. 2) Add calls to Win32 sleep function to wait for the WebBrowser control 3) Queried the Webbrowser to make sure it was in a Navigation Complete state.

    And here is what fixed it: Added "DoEvents" liberally around the code referencing and automating the webbrowser control:

    Dim HTMLEmail As HTMLDocument
    Dim DIV As HTMLDivElement
    DoEvents
    Set HTMLEmail = Me.Email_MainBrowser.Controls("MyBrowser").Object.Document
    Set DIV = HTMLEmail.getElementById("MyText")
    DoEvents
    DIV.innerHTML = HTML
    DoEvents
    

    I have not worked out the minimum number of DoEvents needed; it is probably just one strategically placed. I also still check to make sure the webbrowser control is in the Natigation complete state, but I'm sure this is a bug deep in the Webbrowser control. One that will probably never be fixed.

提交回复
热议问题