首页 > 解决方案 > 在 VBA 中使用脚本时出错

问题描述

**Public Sub WebTest()
    Dim keys As New keys, arr(), ws As Worksheet, i As Long
    Dim temp1(), temp2() As String
    'Set ws = ThisWorkbook.Worksheets("Sheet1") '<==Adjust to your sheet
    arr = Application.Transpose(Selection) '<== Adjust to your range
    With bot
        .Start "Chrome"
        .Get "url here"
        For i = LBound(arr) To UBound(arr)
            If Not IsEmpty(arr(i)) Then
                If i > 1 Then
                    .ExecuteScript "window.open(arguments[0])", "url here"
                    .SwitchToNextWindow
                End If
                .FindElementByCss("[name=q]").SendKeys arr(i)
                .SendKeys bot.keys.Enter
            End If
        Next
    End With
End Sub**

我正在使用上面的代码从 excel 中获取值并在特定的 url 中搜索。在执行加载两个搜索并在此之后显示错误为“运行时错误 17 javascript 错误非法调用”时,我不知道代码中缺少什么或需要更改的内容。

标签: javascriptvbagoogle-chromeurlruntime-error

解决方案


推荐阅读