vba IE.navigate2 因保护模式关闭而失败
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6909226/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
IE.navigate2 fails with protected mode off
提问by Daniel Kreiseder
I'm automating IE8 from Excel VBA (Excel 2010, Windows 7)
我正在从 Excel VBA (Excel 2010, Windows 7) 自动化 IE8
Set IE = CreateObject("InternetExplorer.Application")
IE.Navigate2 URL
If URL is a website in a zone where IE protected mode is on, everything is fine.
如果 URL 是处于 IE 保护模式的区域中的网站,则一切正常。
If URL is a website in a zone where IE protected mode is off, the script fails (IE becomes automatically visible, IE object is lost in VBA - automation error).
如果 URL 是处于 IE 保护模式关闭的区域中的网站,则脚本将失败(IE 自动可见,IE 对象在 VBA 中丢失 - 自动化错误)。
Is there any way to enable navigate2 in zones with protected mode off?
有没有办法在保护模式关闭的区域中启用导航 2?
回答by EricLaw
What you want to do is create an instance of IE running at Medium Integrity, and navigate that. Typically, you'd do that by using CoCreateInstance(CLSID_InternetExplorerMedium). Currently, there's no ProgID that points at this CLSID, however, it you can easily create one:
您要做的是创建一个在 Medium Integrity 下运行的 IE 实例,然后导航它。通常,您可以通过使用 CoCreateInstance(CLSID_InternetExplorerMedium) 来做到这一点。目前,没有指向此 CLSID 的 ProgID,但是,您可以轻松创建一个:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\InternetExplorer.ApplicationMedium]
[HKEY_CLASSES_ROOT\InternetExplorer.ApplicationMedium\CLSID]
@="{D5E8041D-920F-45e9-B8FB-B1DEB82C6E5E}"
You can then invoke this object thusly:
然后你可以这样调用这个对象:
CreateObject("InternetExplorer.ApplicationMedium")
I explain a bit more fully over here: http://blogs.msdn.com/b/ieinternals/archive/2011/08/03/internet-explorer-automation-protected-mode-lcie-default-integrity-level-medium.aspx
我在这里更全面地解释一下:http: //blogs.msdn.com/b/ieinternals/archive/2011/08/03/internet-explorer-automation-protected-mode-lcie-default-integrity-level-medium .aspx
回答by Anders
Getting InternetExplorer.ApplicationMedium by CLSID:
通过 CLSID 获取 InternetExplorer.ApplicationMedium:
Set IE = GetObject("new:{D5E8041D-920F-45e9-B8FB-B1DEB82C6E5E}")