使用VBA自动化边缘模式(没有第三方软件)
当我一直在研究这个主题时,我正在创建一篇文章,并发现了一些矛盾的答案,该答案围绕着具有没有第三方应用程序的VBA自动化模式的能力(请参见下面的解决方案)。
我目前有一个在IE中完成以下操作的应用程序:
- 验证IE的实例是否已经打开并导航到特定的URL;
- 如果以上不是正确的话,可以创建一个新的IE实例;
- 从HTML文档中获得可用的数据;然后
- 单击元素以导航到其他选项卡和页面。
在IE贬值之前,我不确定如何指示代码与Edge IE模式专门通信,而不是尝试创建Internet Explorer的全新实例。 是否有人可能有我可以参考的特定示例
? 71994505/9791828“> https://stackoverflow.com/a/a/71994505/9791828
在该线程中,其中一个响应表明这种自动化是可能的。
截至2022年4月25日,您现在可以直接使用VBA自动化Edge模式,而无需任何其他第三方软件。我和我的同事通过与合作的Microsoft支持团队进行交流后,对以下指南进行了很好的测试。
您需要做什么
您的Windows版本必须至少为20H2。您可以在此处使用此指南检查Windows版本。
您的窗口需要安装以下KBS:KB5011487。或者简单地更新窗口,也应自动安装。您可以在此处使用本指南检查Windows更新历史记录。
最终在窗口上安装以下注册表键,然后重新启动:
Windows注册表编辑器版本5.00
[HKEY_LOCAL_MACHINE \ SOFTWARE \ PALICIES \ MICROSOFT \ Internet Explorer \ main]“ notifyDisableIeoptions” = dword:00000002
[HKEY_LOCAL_MACHINE \ SOFTWARE \ PALICIES \ MICROSOFT \ Internet Explorer \ Main \ EnterPriseMode] “ EnableGlobalWindowListinieMode” = DWORD:00000001
根据MS支持团队,上述方法应在2029年之前起作用。我相信可能很快就会发布有关此的官方文件。
在上述步骤之后,VBA将能够与Edge IE模式进行交互,就好像它是Internet Explorer窗口一样。您当前自动化InternetExplorer的代码。应用对象也将使用Edge IE模式。
社区专家之一说,没有硒和驾驶员,这是不可能的。
如果不是硒,我认为您不能与Edge IE模式自动化。
与Edge IE模式自动化的唯一方法是使用IEDRIVER。您不能只使用VBA做到这一点。您需要:
定义具有其他属性的Internet Exploroptions,该属性指向Microsoft Edge浏览器。
启动Internet ExplorerDriver的实例,然后通过Internet ExpplorerOptions。 IEDRIVER启动Microsoft Edge,然后以IE模式加载您的Web内容。
有关更多信息,您可以参考此文档
I'm creating a post as I've been researching this topic and have found some contradicting answers surrounding the ability to automate Edge IE Mode with VBA without third-party applications (see solutions below).
I currently have an app that accomplishes the following in IE:
- Verifies whether or not an instance of IE is already open and navigated to a specific URL;
- Creates a new IE instance if the above isn't true;
- Scrapes data available from the HTML doc; and
- Clicks elements to navigate to other tabs and pages.
Leading up to the deprecation of IE, I'm unsure how to direct my code to specifically communicate with Edge IE mode instead of it attempting to create a brand new instance of Internet Explorer. Does anyone possibly have specific examples that I could reference?
Response 1: https://stackoverflow.com/a/71994505/9791828
In that thread, one of the responses indicates that this automation is possible.
As of 25th April 2022, you can now directly automate Edge IE Mode with VBA without any additional third party-software. The below guidance has been well tested by me and my colleagues after obtaining it from exchanging with our partnered Microsoft Support team.
What You Need to Do
Your Windows version needs to be at least 20H2. You can check your Windows version with this guide here.
Your Windows needs to have the following KBs installed: KB5011487. Or simply update your Windows and this should be automatically installed as well. You can check your Windows update history with this guide here.
Finally install the below registry keys on your Windows and restart:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Internet
Explorer\Main] "NotifyDisableIEOptions"=dword:00000002[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Internet
Explorer\Main\EnterpriseMode]
"EnableGlobalWindowListInIEMode"=dword:00000001Per the MS Support team, the above method should work until 2029. Official documentation on this might be coming soon I believe.
After the above steps, VBA shall be able to interact with Edge IE Mode as if it is an Internet Explorer window. Your current code that automates the InternetExplorer.Application object will work with Edge IE mode as well.
Response 2: https://learn.microsoft.com/en-us/answers/questions/829365/vba-automation-with-edge-ie-mode.html
One of the community experts stated that this isn't possible without Selenium and a driver.
If Selenium is not an option, I think you can't automate with Edge IE mode.
The only way to automate with Edge IE mode is using IEDriver. You can't do it with only VBA. You need to:
Define InternetExplorerOptions with additional properties that point to the Microsoft Edge browser.
Start an instance of InternetExplorerDriver and pass it InternetExplorerOptions. IEDriver launches Microsoft Edge and then loads your web content in IE mode.
For more information, you can refer to this doc.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不幸的是,到目前为止,使用VBA在边缘浏览器中实现IE模式自动化似乎是不可能的。即使使用SeleniumBasic,由于没有
Internet ExpplorerOptions
类别,因此您无法使用VBA在IE模式下运行自动化。但是,目前,您不必担心IE退休后的IE自动化。响应1后,我试图禁用IE11浏览器,事实证明,VBA代码仍然成功启动了IE浏览器窗口。您可以预期您的VBA代码在IE退休后会起作用。
有关IE退休的更多信息,请阅读本文:
Unfortunately, it seems to be impossible to implement IE mode automation in the Edge browser using VBA so far. Even with SeleniumBasic, since there's no
InternetExplorerOptions
class or the like available, you cannot run the automation in the IE mode using VBA.However, for now you don't have to worry about IE automation after the IE retirement. I tried to disable the IE11 browser following Response 1, and it turned out that VBA code still successfully launched IE browser window. You could expect your VBA code will work after the IE retirement.
For more information of IE retirement, please read this article:
我的VBA(v7.1.1126)直接从IE询问HTML;因此,我已经使用了带有Python(v3.10.6)的Selenium将等效数据从Chrome提取,并将其保存到文本文件中,然后我的VBA可以访问和解释。 VBA可以直接致电Python。
步骤1:安装最新的稳定[Python] [1]
步骤2:安装最新的稳定[Pycharm] [2],并从同一链接中阅读如何使用它
。单击右上方附近的三个点。单击设置,然后关于Chrome查看Chrome的版本。下载相应的驱动程序[此处。] [3]在Pycharm路径文件夹中保存驱动程序
步骤4:创建一个新项目并安装软件包Selenium和WebDriver-Manager,如PYCHARM链接上方所述,
步骤5:创建一个新的空白Python文件vba.py在下一步中由VBA更新此Willl。
步骤6:将此代码添加到新的VBA过程中,以确保它对您有效:
python代码将VBA插入vba.py上方,并带有其他评论:
''python
My VBA (v7.1.1126) interrogates the HTML from IE directly; so I have used Selenium with Python (v3.10.6) to pull the equivalent data from Chrome and save it to a text file which my VBA can then access and interpret. VBA can call Python directly.
Step 1: Install the latest stable [Python][1]
Step 2: Install the latest stable [PyCharm][2] and read how to use it from the same link
Step 3: Open Chrome. Click on three dots near top right. Click on Settings then About Chrome to see the version of your Chrome. Download the corresponding driver [here.][3] Save the driver in the PyCharm PATH folder
Step 4: Create a new project and install the packages selenium and webdriver-manager as explained in the PyCharm link above
Step 5: Create a new blank Python file vba.py This willl be updated by the VBA in the next step.
Step 6: Add this code to a new VBA procedure to ensure that it works for you:
Python code inserted by VBA into vba.py above with additional comments:
'''python