VBA Internet Explorer 自动化“权限被拒绝" [英] VBA Internet Explorer Automation 'Permission Denied'

查看:175
本文介绍了VBA Internet Explorer 自动化“权限被拒绝"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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.

错误状态为运行时错误 70:权限被拒绝"

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

请不要建议更改代码.代码没有任何问题.此宏适用于 10 台计算机中的 9 台.这不是时间问题(即使我手动执行,我仍然会收到错误消息).我知道还有其他方法可以声明 Internet Explorer 对象.我试过使用 CreateObject 和所有这些东西.这都不重要.以管理员身份运行也无济于事.

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.

这只是问题的一个简单示例(我们实际上正在自动化更复杂的任务).所以请不要问为什么要进行goodle搜索?"请不要问你想做什么".我需要解决这个问题.我不需要重新编写代码.

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.

我们使用 Windows XP、Internet Explorer 7 和 Office 2003.某些原因导致随机人员无法自动化 Internet Explorer.不是用户问题,是电脑问题.我的意思是在罪魁祸首的计算机上,无论哪个用户登录,都没有人可以自动化.但同一个用户可以使用不同的计算机,一切都很好.因此,它可能是本地计算机上的注册表设置或类似的设置.这里所有的电脑都以相同的方式设置,相同的规格,相同的软件.

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.

我在谷歌上搜索过,谷歌搜索过,谷歌搜索过,谷歌搜索过.不幸的是,运行时错误 70 似乎是一个包罗万象的问题,许多用户报告了不同症状的错误.就我而言,我还没有找到解决方案,否则我不会在这里问.

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.

我们可以解决的唯一方法是让 IT 完全重新加载硬盘驱动器上的所有内容.干净的刷新,包括操作系统.这解决了问题,但也迫使用户将他们的机器重新设置为他们以前的方式并重新安装所有软件和所有内容.这不是一个好的解决方案.机器上某处有一个设置会导致这种情况,否则刷新不会产生影响.我想知道那个设置是什么(我感觉是注册表设置).

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).

感谢任何帮助,谢谢.

推荐答案

在测试了以上所有建议的修复甚至更多之后,我确信这是一个奇怪的错误,当有不同的安全区域时,IE 会调用子进程的事件处理一个网站.

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

每次导航到新页面或其他可能导致网站重新加载的事件(例如点击提交按钮或类似按钮)后,添加此代码段.

上面的 Dan 建议在你的代码中随意添加 DoEvents 语句,这对我来说并没有 100% 成功.相反,我建议在适用的地方添加上述代码.

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.

感谢 Dan,如果没有您的评论,我永远不会知道!

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

此方法相对于其他建议修复的优点的简短摘要:

  • 如果你愿意,你可以坚持后期绑定(将 IE 作为对象)
  • 您可以坚持创建 InternetExplorer 对象(而不是 InternetExplorerMedium)
  • 您无需更改 IE 中的安全区域设置
  • 在您的应用程序中没有不必要的等待时间
  • 您摆脱了错误 70 - 权限被拒绝
  • 您摆脱了丢失的会话,即运行时错误‘-2147417848 (80010108)’:自动化错误调用的对象已与其客户端断开连接."
  • 您摆脱了接口问题,即运行时错误‘-2147023179 (800706b5)’:自动化错误接口未知"

使用此方法您不需要的所有内容的摘要:

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

  • InternetExplorerMedium 对象
  • 一般早期绑定
  • 参考 Microsoft Internet Controls
  • 参考 Microsoft Shell 控件和自动化
  • 奇怪的错误处理
  • 无需检查代码中的 IE.Busy
  • Application.wait 或 sleep 导致不必要的猜测延迟

我只包含上面的总结,因为我已经看到了所有建议的解决方法,并且到目前为止我已经亲自尝试过但没有运气.

基于 OP 问题的示例代码:

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.

最好的问候帕特里克

这篇关于VBA Internet Explorer 自动化“权限被拒绝"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆