VBA脚本在Intranet上失败

我目前正在使用Office 2010,Visual Basic for Applications 7和Internet Explorer 9。

目前我遇到的问题是,使用IE对象似乎在我们的内部网上失败,我想知道是否有这个修复。

function代码:

Dim IE As Object Set IE = CreateObject("InternetExplorer.Application") IE.Navigate "http://www.google.com" WaitUntilReady IE 'Application.Wait (Now + TimeValue("00:00:10")) 'IE.Visible = True MsgBox (IE.Document.body.innerHTML) 

破码:

 Dim IE As Object Set IE = CreateObject("InternetExplorer.Application") IE.Navigate "http://intranet/" WaitUntilReady IE 'Application.Wait (Now + TimeValue("00:00:10")) 'IE.Visible = True MsgBox (IE.Document.body.innerHTML) 

function代码完全是它应该的。 创build一个IE对象,该对象不会在屏幕上显示,并返回带有google.com的HTML代码内容的消息框

破碎的代码加载我们的Intranet主页,在VISIBLE IE窗口中,并返回这个错误:

 Run-time error '-2147417848 (80010108)' Automation error The object invoked has disconnected from its clients 

我已经通过Excel VBA控制IE浏览器本地Intranet ,它build议使用IP地址,而不是内部网/这不工作,因为IP指向一个不同的启animation面。

我也试过使用

 Set IE = New InternetExplorerMedium 

但是,这个A也似乎不起作用,而B-意味着要确保所有的同事都启用这个引用。

此外,我已经尝试加载google.com第一,然后让它导航到内联网/,这也没有帮助。

任何人有任何build议? 从我的理解,加载Intranet /导致IE以某种方式从Excel断开连接?

所以! 经过几天的研究,完全丧失了正在发生的事情,我在另一篇文章中偶然发现有人在谈论Intranet兼容模式。

在Intranet中强制使用“Internet Explorer 8”浏览器模式

当我读到这个时,发生了点击头部的事情,意识到如果IE加载的兼容性,这将解释为什么Excel VBAmacros失去了对IE的控制,因为兼容模式可能作为单独的IE实例加载。

设置> Internet选项>安全>本地Intranet>站点>

禁用“自动检测内联网”并启用“包含所有networkingpath(UNC)”可以很好地修复我所遇到的错误。

 'simply replace -seem to work ' Set ie = CreateObject("InternetExplorer.Application") Set ie = New InternetExplorerMedium 

另一种scheme

 Set IE = CreateObject("InternetExplorer.Application") IE.Navigate ("http://URLOnMyIntranet/site.html") IE.Visible = True Set IE = nothing Set objShellApp = CreateObject("Shell.Application") For Each objWindow In objShellApp.Windows Debug.Print objWindow.LocationName If LCase(objWindow.LocationName) = LCase("Your windows name, use debug to find out") Then Set IE = objWindow End If Next`enter code here` 

也看到这个post