问题
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