如何进行非常规方法

时间:2019-04-09 19:43:19

标签: excel vba

我是XMLHHTP的新手,我只是在一些人的在线帮助下编写了以下代码,并意识到我需要使其异步,因为工作簿需要访问数百个URL。

如果有人可以研究并将其转变为异步信号,我将不胜感激。

Sub GetInfo()

    Dim Http As New XMLHTTP60, Html As New HTMLDocument
    Dim lastrow As Long, i As Long
    Dim sdd As String
    Dim add As Variant
    Dim url As Range

    i = 2

    For Each url In Range(Cells(3, "J"), Cells(Rows.Count, "J").End(xlUp))
        With Http
            .Open "GET", url, False
            .send
            Html.body.innerHTML = .responseText
        End With

        On Error Resume Next
        sdd = Html.querySelector("span[itemprop='price']").getAttribute("content")
        i = i + 1
        Sheet1.Cells(i, "K") = sdd

    Next url


End Sub

1 个答案:

答案 0 :(得分:1)

我得到了你的答案,请看一下本演练...

http://dailydoseofexcel.com/archives/2006/10/09/async-xmlhttp-calls/

我希望有帮助。