VBA - 如何在关注超链接后​​下载网页

时间:2017-04-12 08:19:32

标签: excel vba excel-vba

我目前正在运行以下代码,该代码会打开我在列中的所有链接。但是,在打开链接之后,因为它打开了很多标签(如预期和预期的那样),我希望它然后将网页的内容下载到pdf并将它们存储在我的机器上的文件夹中。

Sub Test()

    Dim Sh As Worksheet
    Dim Rng As Range
    Dim Cell As Range
    Set Sh = Worksheets("Sheet1")

    With Sh
        Set Rng = .Range("L3:L" & .Cells(.Rows.Count, "L").End(xlUp).Row)        
    End With

    For Each Cell In Rng
        ThisWorkbook.FollowHyperlink Cell.Text
    Next Cell

End Sub

1 个答案:

答案 0 :(得分:0)

好的,所以这将从网页导入所有内容并将其放在Cell A1中。如果这是您的意图,您可以轻松地将单元格的内容转储为PDF(另存为PDF)。

Sub Test()
    Dim IE As Object

    Set IE = CreateObject("InternetExplorer.Application")
    With IE
        .Visible = True
        .Navigate "http://finance.yahoo.com" ' should work for any URL
        Do Until .ReadyState = 4: DoEvents: Loop

            Range("A1").Value = .document.body.innertext

            .Quit
        End With

End Sub