Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 批量打开URL_Excel_Vba_Url_Web Scraping_Automation - Fatal编程技术网

Excel 批量打开URL

Excel 批量打开URL,excel,vba,url,web-scraping,automation,Excel,Vba,Url,Web Scraping,Automation,我有一个工作表,其中J列包含一个网站列表,从第3行开始。我想有一个宏,它将批量打开在同一浏览器窗口的不同标签所有的网站。 我有下面的现有代码 Sub Test() Dim ie As Object Dim c As Range Set ie = CreateObject("InternetExplorer.Application") With ie .Visible = True For

我有一个工作表,其中J列包含一个网站列表,从第3行开始。我想有一个宏,它将批量打开在同一浏览器窗口的不同标签所有的网站。 我有下面的现有代码

Sub Test()
    Dim ie          As Object
    Dim c           As Range

    Set ie = CreateObject("InternetExplorer.Application")

    With ie
        .Visible = True

        For Each c In Sheets("Common").Range("J3:J" & Cells(Rows.Count, 1).End(xlUp).Row)
            .Navigate c.Value, CLng(2048)
        Next c
    End With
End Sub

它在很大程度上起作用。但不知何故,它会在浏览器窗口中打开没有值的选项卡。

您应该指定前面工作表的名称,因为您的工作表隐式使用activesheet,这很容易出现错误。例如

ThisWorkbook.Worksheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row 
通过调试,您似乎找到了错误的xlUp结束行,因此请使用xlDown(假设您知道URL之间没有空单元格)


如果你想使用Chrome考虑。确保最新的ChromeDriver.exe位于selenium文件夹中,并且添加了VBE>工具>引用>selenium类型库引用。

是否有其他方法不使用selenium?这取决于您的命令行的性能,您可以使用URL编写bat文件,并通过VBAThanks中的shell在该文件上执行循环,以将我定向到该链接。看起来信息量很大。但是我不想使用它,因为它需要我重新编写代码,因为我要处理列中的URL列表。您可以使用相同的想法,但将URL从工作表连接到shell命令中。这不起作用,但可以。我可以用Internet Explorer解决问题。
Sheets("Common").Range("J3:J" & Sheets("Common").Cells(Rows.Count, 1).End(xlDown).Row)