Concatenation of string and looped value

大城市里の小女人 提交于 2019-12-13 20:39:34

问题


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"))

I am attempting to loop through the values Number in a column range accountNumber, adding them to the end of the URL given. This will ultimately visit multiple webpages, adding to the QueryTables each time.


回答1:


Answer for length :

From 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

You stated you were getting an Invalid Web Query. i don't think you need to append all values to one query. i think you need to run multiple queries, each with one value from the range.

I also think it's not going to be a good idea to have the same destination for all of them.



来源:https://stackoverflow.com/questions/33815916/concatenation-of-string-and-looped-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!