如何制作Asyc方法

问题描述 投票:0回答:1

我是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
excel vba
1个回答
1
投票

我得到了你的答案,看看这个演练......

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

我希望有所帮助。

© www.soinside.com 2019 - 2024. All rights reserved.