3

我正在从 Excel VBA(Excel 2010,Windows 7)自动化 IE8

Set IE = CreateObject("InternetExplorer.Application")
IE.Navigate2 URL

如果 URL 是 IE 保护模式打开的区域中的网站,则一切正常。

如果 URL 是 IE 保护模式关闭的区域中的网站,则脚本将失败(IE 自动可见,IE 对象在 VBA 中丢失 - 自动化错误)。

有什么方法可以在保护模式关闭的区域中启用 navigate2?

4

2 回答 2

11

您要做的是创建一个在中等完整性下运行的 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}"

然后,您可以调用此对象:

CreateObject("InternetExplorer.ApplicationMedium")

我在这里更全面地解释一下:http: //blogs.msdn.com/b/ieinternals/archive/2011/08/03/internet-explorer-automation-protected-mode-lcie-default-integrity-level-medium .aspx

于 2011-08-02T13:01:35.137 回答
8

通过 CLSID 获取 InternetExplorer.ApplicationMedium:

Set IE = GetObject("new:{D5E8041D-920F-45e9-B8FB-B1DEB82C6E5E}")
于 2011-08-03T21:47:01.467 回答