vba 从 Internet Explorer 切换到 Microsoft Edge
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31784247/
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
Switching from Internet Explorer to Microsoft Edge
提问by Charlie
After the recent release of Windows 10, including the new browser - Microsoft Edge - would anyone simply know how to open Microsoft Edge browser via Excel VBA. I have tried searching the website without any luck.
在最近发布的 Windows 10 之后,包括新的浏览器 - Microsoft Edge - 任何人都知道如何通过 Excel VBA 打开 Microsoft Edge 浏览器。我试过在没有任何运气的情况下搜索网站。
This is the current basic Excel VBA coding I use to open the Internet Explorer:
这是我用来打开 Internet Explorer 的当前基本 Excel VBA 编码:
Sub xyz()
Dim Browser As SHDocVw.InternetExplorer 'Microsoft Internet Controls
Dim HTMLdoc As MSHTML.HTMLDocument 'Microsoft HTML Object Library
Dim URL As String
URL = "http://www.bbc.co.uk/news"
Set Browser = New InternetExplorer
Browser.Silent = True
Browser.navigate URL
Browser.Visible = True
Do
Loop Until Browser.readyState = READYSTATE_COMPLETE
Set HTMLdoc = Browser.document
End Sub
This is a very straight forward piece of VBA coding to open the BBC website for example.
例如,这是一个非常简单的 VBA 编码,用于打开 BBC 网站。
However, what is the new piece of coding to open Microsoft Edge?
但是,打开 Microsoft Edge 的新编码是什么?
回答by ChipsLetten
According to MS here, IE11 ships with Windows 10
根据 MS here,IE11 附带 Windows 10
The default browser for Windows 10 is Microsoft Edge, which is powered by our new rendering engine and is our path forward for the Web on Windows. Site developers should focus their testing on Microsoft Edge for new and existing experiences. Internet Explorer 11 will be included for some legacy scenarios and users will be have the option to choose it as the default browser, like with any other browser.
Windows 10 的默认浏览器是 Microsoft Edge,它由我们的新渲染引擎提供支持,是我们在 Windows 上的 Web 前进的道路。站点开发人员应将测试重点放在 Microsoft Edge 上,以获得新的和现有的体验。Internet Explorer 11 将包含在某些旧方案中,用户可以选择将其作为默认浏览器,就像使用任何其他浏览器一样。
So existing code for IE should continue to work. Not tried it though.
所以现有的 IE 代码应该继续工作。不过没试过。
Some technical stuff on Edge can be found here
可以在此处找到 Edge 上的一些技术内容
As of Mon 10-Aug-2015, I have upgraded one PC from Win 7 Pro SP1 to Win 10 Pro and the code you supplied works fine. IE11 runs fine and shows the website. The IE11 download pageconfirms that I've already got it installed.
截至 2015 年 8 月 10 日星期一,我已将一台 PC 从 Win 7 Pro SP1 升级到 Win 10 Pro,您提供的代码运行良好。IE11 运行良好并显示网站。在IE11下载页面确认我已经有安装了它。
回答by user5378755
I had a similar issue upon updating to Windows 10. Turns out 'Microsoft Internet Controls' and 'Microsoft HTML Object Library' had been "removed" from 'References'. Adding them resolved the problem and code worked fine without requiring any alterations. Don't know if this helps.
我在更新到 Windows 10 时遇到了类似的问题。原来“Microsoft Internet Controls”和“Microsoft HTML Object Library”已从“References”中“删除”。添加它们解决了问题,代码运行良好,无需任何更改。不知道这是否有帮助。
回答by BradH
This may not be an answer but it worked for me.
这可能不是答案,但对我有用。
The Internet Explorer object will still open through VBA in Windows 10 using IE11. However, I had to ask Cortana to open IE11 first so it would sort out all of it's "first time use" pop-ups and what not. "Welcome to IE11" and "Let's get started" etc.
Internet Explorer 对象仍将在使用 IE11 的 Windows 10 中通过 VBA 打开。但是,我必须先让 Cortana 打开 IE11,这样它才能解决所有“第一次使用”弹出窗口和其他问题。“欢迎使用 IE11”和“让我们开始吧”等。
Once I got through all that and closed the browser. I re-ran my macro and the browser object came up fine and worked as normal. Hope this helps someone.
一旦我完成了所有这些并关闭了浏览器。我重新运行了我的宏,浏览器对象正常运行并正常工作。希望这可以帮助某人。
P.S. I'm using the CreateObject method of creating the browser window.
PS 我正在使用 CreateObject 方法来创建浏览器窗口。
回答by tresf
how to open Microsoft Edge browser via Excel VBA
如何通过 Excel VBA 打开 Microsoft Edge 浏览器
VBS/VBA uses the COM object model (ActiveX) to communicate with desktop processes and this feature will not be made available for Edge.
VBS/VBA 使用 COM 对象模型 (ActiveX) 与桌面进程通信,Edge 将无法使用此功能。
Fortunately newer cross-browser solutions (i.e. WebDriver) exist for automation and Edge adopts these new standards. Unfortunately, to use them, the techniques used will need to change.
幸运的是,存在用于自动化的较新的跨浏览器解决方案(即 WebDriver),Edge 采用了这些新标准。不幸的是,要使用它们,所使用的技术需要改变。
Duplicate of Will Microsoft Edge support COM automation (InternetExplorer object)?.

