要从Internet Explorer转换为Edge或Chrome浏览器的VBA脚本 [英] VBA Script to convert from internet explorer to Edge or chrome browser
本文介绍了要从Internet Explorer转换为Edge或Chrome浏览器的VBA脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在寻找以下代码以从Internet Explorer转换为Edge浏览器,请求您帮助对其进行排序。
Sub CHECK_STATUS()
Dim cell As Range
Dim IntExp As Object
Set IntExp = CreateObject("InternetExplorer.Application")
IntExp.Visible = False
For Each cell In Range("A2:A20000")
'Here A2 is cell Address where we have stored urls which we need to test.
If Left(cell.Value, 4) = "http" Then
' Goto web page
IntExp.navigate cell.Text
' Below loop will run until page is fully loaded
Do While IntExp.Busy Or IntExp.readyState <> 4
DoEvents
Loop
' Now use text which you want to search , error text which you want to compare etc.
Dim ieDoc As Object
Set ieDoc = IntExp.document
If ieDoc.getElementsByClassName("box-content").Length <> 0 Then
cell.Offset(, 1).Value = ieDoc.getElementsByClassName("box-content")(0).innerText
End If
End If
Next cell
IntExp.Quit
Set IntExp = Nothing
End Sub
推荐答案
您需要使用SeleniumBasic在VBA中自动执行边缘。SeleniumBasic是一个基于SeleniumBasic的浏览器自动化框架,适用于VB.Net、VBA和VBScrip。
我同意QHarr的意见,您也可以按照以下步骤使用SeleniumBasic自动执行Edge浏览器:
- 从this link下载并安装最新版本的SeleniumBasic v2.0.9.0。
- 从this link下载相应版本的Edge WebDriver。
- 找到
C:Users\%username%AppDataLocalSeleniumBasic
C:Users\%username%AppDataLocalSeleniumBasic
中SeleniumBasic的路径(也可能在此路径C:Program FilesSeleniumBasic
),将Edge WebDrivermsedgedriver.exe
复制到此路径。 - 将
msedgedriver.exe
重命名为edgedriver.exe
。 - 打开Excel并编写VBA代码。
- 在VBA代码界面中,单击工具&>引用,添加硒类型库引用,然后单击确定保存。
- 我编写了一个简单的VBA代码来展示如何使用SeleniumBasic自动化Edge。您可以参照,根据自己的需求修改代码:
Public Sub Selenium()
For Each cell In Range("A2:A20000")
Dim bot As New WebDriver
If Left(cell.Value, 4) = "http" Then
bot.Start "edge", cell.Value
bot.Get "/"
If Not bot.FindElementsByClass("box-content") Is Nothing Then
cell.Offset(, 1).Value = bot.FindElementsByClass("box-content")(1).Text
End If
End If
bot.Wait 3000
bot.Quit
Next cell
End Sub
这篇关于要从Internet Explorer转换为Edge或Chrome浏览器的VBA脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文