字符串和循环值的串联

时间:2015-11-19 22:56:56

标签: string excel vba concatenation

For Each Number In accountNumber
    Dim urlString As String
    urlString = "http://www.prad.org/CamaDisplay.aspx?OutputMode=Display&SearchType=RealEstate&ParcelID=" & accountNumber.Value
    Set dataSet = ActiveSheet.QueryTables.Add( _
        Connection:="URL;urlString, _
        Destination:=ThisWorkbook.Worksheets(2).Range("A1"))

我正在尝试遍历列范围Number中的值accountNumber,并将它们添加到给定的URL的末尾。这将最终访问多个网页,每次都会添加QueryTables

1 个答案:

答案 0 :(得分:0)

答案长度:

来自previous question

Sub FindData()

    Dim accountNumber As Range
    Set accountNumber = Range(Range("A2"), Range("A2").End(xlDown))
    Dim dataSet As QueryTable

    For Each Number In accountNumber
        Set dataSet = ActiveSheet.QueryTables.Add( _
        Connection:="URL;http://www.prad.org/CamaDisplay.aspx?OutputMode=Display&SearchType=RealEstate&ParcelID=" & Number.Value, _
        Destination:=ThisWorkbook.Worksheets(2).Range("A1")


        With dataSet
           .RefreshOnFileOpen = False
           .WebFormatting = xlWebFormattingNone
           .BackgroundQuery = True
           .WebSelectionType = xlSpecifiedTables
           .WebTables = "3"
        End With

        With Application
             dataSet.Refresh BackgroundQuery:=False
        End With
    Next Number
End Sub

您说您收到了无效的网络查询。我认为您不需要将所有值附加到一个查询中。我认为你需要运行多个查询,每个查询都有一个范围内的值。

我也认为为所有人提供相同的目的地并不是一个好主意。