3
Dim IE as New InternetExplorer
IE.Visible = True

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

Do Until IE.Busy = False
Loop

IE.document.getElementsByTagName("Input")(3).Value = "Search Term"

IE.document.Forms(0).Submit     <------ This line results in error.

The error states Run-time error 70: 'Permission Denied'

Please do not suggest code alterations. There is NOTHING wrong with the code. This macro works on 9 out of 10 computers. It is NOT a timing issue (I still get the error even if I step through manually). I know there are other ways to declare the internet explorer object. I have tried using CreateObject and all that stuff. None of it matters. Running as administrator does not help either.

This is just a simple example of the problem (we are actually automating much more complex tasks). So please do not ask "why do you want to do a goodle search?" and please do not ask "what are you trying to do". I need this problem solved. I don't need my code re written.

We use Windows XP, Internet Explorer 7, and Office 2003. Something is causing random people to not be able to automate internet explorer. It is not a user issue, but a computer issue. What I mean is on the culprit computers nobody can automate no matter which user logs in. But the same user can use a different computer and everything is fine. Therefore, it is likely a registry setting on the local machine or something like that. All computers are set up the same way here, same specs, same software.

I have googled and googled and googled and googled. Unfortunately run-time error 70 seems to be a catch all and a lot of users report the error for different symptoms. In my case I have not found a solution otherwise I would not be asking here.

The only way we can solve it is to have IT completely reload everything on the hard drive. A clean refresh including the operating system. That takes care of the problem but it also forces the user set their machine up again to the way they had it before and reinstall all of the software and everything. That is not a good solution. There is a setting somewhere on the machine causing this or the refresh would not have an effect. I want to know what that setting is (my feeling is it is a registry setting).

Any help is appreciated, thanks.

Dennis Williams
  • 31
  • 1
  • 2
  • 4

8 Answers8

5

After testing all above suggested fixes and even more, I am positive this is a weird bug with Eventhandling of child Processes invoked by IE whenever there are different security zones on one website.

Cut to the chase, here is the solution:

'Craziest workaround ever due to bugged IE Eventhandling
Do While IE.ReadyState = 4: DoEvents: Loop 
Do Until IE.ReadyState = 4: DoEvents: Loop

Add this code piece every time after navigating to a new page or other events that might cause the website to reload, like clicking on a submit button or similar.

Dan above suggested to add DoEvents statements liberally in your code, which did not 100% do the trick for me. Instead, I suggest to add above code whereever applicable.

Kudos to Dan, without your comment I would've never figured it out!

Short summary of the BENEFITS this method has over other suggested fixes:

  • You can stick to late binding if you wish (Dim IE as Object)
  • You can stick creating a InternetExplorer object (as opposed to i.e. InternetExplorerMedium)
  • You don't need to alter the security zone settings in IE
  • No unnecessary wait times in your application
  • You get rid of Error 70 - Permission denied
  • You get rid of lost sessions i.e. "Run-time error '-2147417848 (80010108)': Automation error The object invoked has disconnected from its clients."
  • You get rid of interface issues i.e. "Run-time error '-2147023179 (800706b5)': Automation error The interface is unknown"

Summary of all the things YOU DO NOT NEED with this approach:

  • InternetExplorerMedium objects
  • Early binding in general
  • Reference to Microsoft Internet Controls
  • Reference to Microsoft Shell Controls and Automation
  • Weird error handling
  • No need to ever check IE.Busy in your code
  • Application.wait or sleep causing unnecessary guesstimated delays

I'm only including above summary because I've seen all those workarounds suggested and have personally tried them with no luck so far.

Example code based on OP's question:

Dim IE as Object    
Set IE = CreateObject("InternetExplorer.Application")

IE.Visible = True
IE.Navigate("http://www.google.com")

'Craziest workaround ever due to bugged IE Eventhandling
Do While IE.ReadyState = 4: DoEvents: Loop
Do Until IE.ReadyState = 4: DoEvents: Loop

IE.document.getElementsByTagName("Input")(3).Value = "Search Term"
IE.document.Forms(0).Submit     ' this previously crashed

I really hope this will help others in the future. Godspeed to everyone who helped with piecing the solution together.

Best Regards Patrick

must_improve
  • 61
  • 1
  • 8
  • 1
    Thank you so much for this! My solution uses Office 365 sign on with internal and external redirects. I've been using this awful retry approach to get it to work. This solution has just fixed everything! – Casper Alant Jun 21 '18 at 07:55
  • To confirm, after the workaround, the entire page has been parsed and rendered by IE? And the entire DOM is accessible? – TechFanDan Jan 05 '21 at 13:10
  • Following the workaround, `ie.busy` shows True in some cases. – TechFanDan Jan 05 '21 at 17:26
1

I am receiving the same error when automating IE, but instead of fixing, I worked around.

  Label1:
         If myIe Is Nothing Then
             Set myIe = CreateObject("InternetExplorer.Application") 
         End If

         myIe.Navigate URL:=imdbLink

    For Each link In myIe.document.Links
         If Right(link.href, 9) = "/keywords" And Left(link.href, 26) = "http://www.imdb.com/title/" Then
                    mKPlot = link.href 'ERROR GENERATES FROM THIS, SOMETIMES...
         End If
    next link



errHandler:
    If Err.Number = 70 Then
        Debug.Print "permission denied for: |" & title & "|"

        myIe.Quit
        Set myIe = Nothing

        Application.Wait Now + TimeValue("00:00:10")

        Resume Label1:

    End If

Not the sleek registry-fix you were imagining, but it works for me.

1

I was having this exact same problem. Had a script for automating IE that had been working fine for a year. Then out of the blue I started receiving this "permission denied error". I did two things, one of which fixed the problem, but I don't know which one.

  1. I removed the reference to "Microsoft Internet Controls", attempted to compile the project, added the reference to "Internet Controls" back in, and compiled the project.

  2. Removed the 'WithEvents' keyword when declaring the InternetExplorer object since I did not need to capture events events from IE anyway.

I suspect it was the first and that somehow the reference became corrupted and removing at and re-adding it fixed the problem.

Francis
  • 11
  • 1
1

This is a common issue with Internet Explorer automation in VBA. It generally seems to happen after a new page has been loaded. I have had success using a combination of DoEvents, Application.Wait, and setting my HTMLDocument object to Nothing after a new page load.

I have posed sample code below to demonstrate:

Option Explicit

Sub IEAutomation()

    Dim IE As InternetExplorer
    Dim html As HTMLDocument
    Dim i As HTMLHtmlElement
    Dim search_bar_id As String
    Dim submit_button_name As String
    Dim search_term As String

    'Define Variables
    search_bar_id = "lst-ib"
    submit_button_name = "btnK"
    search_term = "Learning VBA"

    'Create IE and Naviagate to Google
    Set IE = CreateObject("InternetExplorer.Application") 'Late Binding
    IE.Visible = True
    IE.navigate "http://www.google.com"

    'Wait for IE To Load
    Do While IE.readyState <> READYSTATE_COMPLETE: DoEvents: Loop

    'Create HTMLDocument Object
    Set html = IE.document

    'Enter Search Term into Search Bar and Click Submit Button
    html.getElementById(search_bar_id).innerText = search_term
    Application.Wait Now + TimeValue("0:00:01")
    html.getElementsByName(submit_button_name)(, 1).Click

    'Wait for New Page to Load (** DoEvents Helps with the Permission Issue **)
    Do While IE.readyState <> READYSTATE_COMPLETE: DoEvents: Loop

    'After Page Loads, Reset HTMLDocument Object and Wait 1 Second Before Recreating It
    Set html = Nothing
    Application.Wait Now + TimeValue("0:00:01") '<<< This seems to really help
    Set html = IE.document

    'Print All Elements In H3 Tags to Immediate Window in VBE
    For Each i In html.getElementsByTagName("H3")
        Debug.Print i.innerText
    Next i

End Sub
Justin
  • 707
  • 7
  • 13
  • Yes this is the only solution which worked for me! THANK YOU! I have tried so much... none of them seemed to work, except this, this is perfect –  Oct 03 '20 at 21:33
  • I'm glad you found the post helpful! – Justin May 24 '21 at 04:36
1

The solution of resetting the HTMLDocument Object works for me too i.e.

'After Page Loads, Reset HTMLDocument Object and Wait 1 Second Before recreating It
Set html = Nothing
Application.Wait Now + TimeValue("0:00:01") '<<< This seems to really help
Set html = IE.document

None of the other solutions have solved my problem.

Asger
  • 11
  • 2
1

The following worked for me. I haven't tested it extensively, but the problem hasn't recurred. I was getting the error intermittently, but always at same point.

Control of the first IE instance seems to die. However, another instance can be created by referencing the first. The dead instance can then be closed, and we carry on.

Set IEa = CreateObject("InternetExplorer.Application")
Set IEa = IE
   'Where IE is the instance that's about to error
SendKeys ("%{F4}")
   'Closes the old window, IE.quit in the code wouldn't work
IEa.Visible = True

Hope this works for someone else, I was getting pretty frustrated.

Brian

PS: My first post on stackoverflow, I think I did the formatting right

yyc123
  • 11
  • 2
0

Try this code for me. This bypasses the need to select/click any element in the browser.

I tested this for INDIA

Sub Sample1() '<~~ Works as expected
    Dim IE As New InternetExplorer
    IE.Visible = True
    IE.Navigate ("http://www.google.co.in/#hl=en&q=" & "Search Term")
End Sub

For UK

Sub Sample2() '<~~ Works as expected
    Dim IE As New InternetExplorer
    IE.Visible = True
    IE.Navigate ("http://www.google.co.uk/#hl=en&q=" & "Search Term")
End Sub

Try this for US (Couldn't Test It as it redirects my request)

Sub Sample3()
    Dim IE As New InternetExplorer
    IE.Visible = True
    IE.Navigate ("http://www.google.com/#hl=en&q=" & "Search Term")
End Sub
Siddharth Rout
  • 147,039
  • 17
  • 206
  • 250
  • Well, that would solve scenarios where GET data is sent to the server through the http request but unfortunately most of our intranet sites we are working with use the POST method. In addition, we are accessing a lot more HTML elements than just forms and the 'permission denied' error occurs during a lot of them. The form submission was just a quick example to illustrate the problem. – Dennis Williams Apr 23 '12 at 17:20
  • Strange enough your code worked for me for the first time then it started giving me errors but on a different line. the moment I used `Sleep`, it started working again. Do you want to test that? – Siddharth Rout Apr 23 '12 at 17:22
  • No I have already tested that. You will not be able to replicate this problem...I can barely replicate it and only on certain computers here at work. I have even made it sleep for 20 or 30 seconds just to make certain it is not a timing thing. – Dennis Williams Apr 23 '12 at 17:23
  • I must say then your question has me baffled :) Let me do some research on it. – Siddharth Rout Apr 23 '12 at 17:25
  • Thank you :) It has me baffled as well. There has to be a security setting somewhere either in office, internet explorer, or the operating system. – Dennis Williams Apr 23 '12 at 17:33
  • Not sure if you have seen this? http://www.fixerrorcodesnow.com/runtime-error-70-permission-denied – Siddharth Rout Apr 23 '12 at 17:44
  • Actually I have already seen that website. That site is actually a ploy to get you to purchase registry cleaning software. There is no information there on my issue. – Dennis Williams Apr 23 '12 at 18:42
  • You might want to search for RIT, RBAT or RCO on the relevant pc? I also have XP and I don't have those keys. – Siddharth Rout Apr 23 '12 at 18:51
  • Those keys didn't exist on any of our computers. Just to be safe though, I added them to the PC in question and it did not alleviate the permission denied error. Back to square one :( – Dennis Williams Apr 24 '12 at 20:29
0

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.

Dan
  • 99
  • 5